PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Scale AI

Update a Neuron Grid

Last updated: May 9, 2026

Quick Overview

This question evaluates competency in matrix/grid manipulation, neighbor-counting logic for eight-directional adjacency, simultaneous state transitions, and space-optimized in-place updates (O(1) auxiliary space).

  • medium
  • Scale AI
  • Coding & Algorithms
  • Software Engineer

Update a Neuron Grid

Company: Scale AI

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given an `m x n` integer matrix `neurons`. - A cell is a **firing** neuron if its value is `0`. - A cell is a **non-firing** neuron if its value is greater than `0`. For each cell, count the number of firing neighbors among its 8 surrounding cells (horizontal, vertical, and diagonal). All updates must be applied **simultaneously** based on the original state of the matrix. Update the matrix using these rules: 1. If a cell is firing (`0`) and **exactly 3** of its neighbors are firing, its new value becomes `6`. 2. If a cell is non-firing and it has **0 or 1** firing neighbors, decrease its value by `2`. 3. If a cell is non-firing and it has **more than 3** firing neighbors, decrease its value by `1`. 4. A cell's value can never go below `0`. 5. In all other cases, the cell keeps its current value. Implement a function to update the matrix state. Follow-up: - First solve it using a copied matrix. - Then optimize the solution to use `O(1)` auxiliary space.

Quick Answer: This question evaluates competency in matrix/grid manipulation, neighbor-counting logic for eight-directional adjacency, simultaneous state transitions, and space-optimized in-place updates (O(1) auxiliary space).

Related Interview Questions

  • Implement Dependency-Aware Task Scheduler - Scale AI (hard)
  • Implement a Dependency-Aware Task Scheduler - Scale AI (easy)
  • Schedule Ready Tasks by Deadline - Scale AI (medium)
  • Implement a Task Processor - Scale AI (medium)
  • Implement multi-head attention and LLM sampling - Scale AI (easy)
Scale AI logo
Scale AI
Feb 22, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
8
0

You are given an m x n integer matrix neurons.

  • A cell is a firing neuron if its value is 0 .
  • A cell is a non-firing neuron if its value is greater than 0 .

For each cell, count the number of firing neighbors among its 8 surrounding cells (horizontal, vertical, and diagonal). All updates must be applied simultaneously based on the original state of the matrix.

Update the matrix using these rules:

  1. If a cell is firing ( 0 ) and exactly 3 of its neighbors are firing, its new value becomes 6 .
  2. If a cell is non-firing and it has 0 or 1 firing neighbors, decrease its value by 2 .
  3. If a cell is non-firing and it has more than 3 firing neighbors, decrease its value by 1 .
  4. A cell's value can never go below 0 .
  5. In all other cases, the cell keeps its current value.

Implement a function to update the matrix state.

Follow-up:

  • First solve it using a copied matrix.
  • Then optimize the solution to use O(1) auxiliary space.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Scale AI•More Software Engineer•Scale AI Software Engineer•Scale AI Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.