Stateful Neuron Matrix Update
Updated
Problem statement
A matrix cell with value 0 is a firing neuron; a positive value is non-firing. Update every cell simultaneously using its up to eight surrounding neighbors.
- A firing neuron becomes
6when exactly three neighbors are firing; otherwise it stays0. - A non-firing neuron loses
2when zero or one neighbor is firing. - It loses
1when more than three neighbors are firing. - With exactly two or three firing neighbors, a non-firing neuron is unchanged.
- Values never fall below zero.
Return the matrix after one simultaneous update.
Function
updateNeuronMatrix(grid: int[][]) → int[][]Examples
Example 1
grid = [[1,0,1],[0,5,0],[1,1,1]]return = [[1,0,1],[0,5,0],[0,1,0]]Moved or new
The center has exactly three firing neighbors and, as a non-firing value, remains 5. Each bottom corner has one firing neighbor and decreases to 0.
Example 2
grid = [[5,5],[5,5]]return = [[3,3],[3,3]]Moved or new
Every neuron has zero firing neighbors, so each value decreases by 2.
Example 3
grid = [[0,0],[0,0]]return = [[6,6],[6,6]]Moved or new
Each corner has exactly three neighbors and all three are firing.
Constraints
1 <= grid.length, grid[i].length <= 1000.- All rows have equal length.
0 <= grid[i][j] <= 1000000000.
More Scale AI Onsite Interview questions
- Task Scheduler with DependenciesONSITE INTERVIEW · Seen Jul 2026
- Best Poker Category with a JokerPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2026
- Format and Validate a Model ResponseONSITE INTERVIEW · Seen Apr 2026
- Clock Hand Angle with Subsecond PrecisionONSITE INTERVIEW · Seen Dec 2025
- Four-Player Matching Card GameONSITE INTERVIEW · Seen Feb 2025
- Rotate an Array to the RightONSITE INTERVIEW · Seen Oct 2024
- Rich-Text Segment Normalization and Bold ToggleONSITE INTERVIEW · Seen Apr 2024
- Minimum Distance Matching in a ForestPHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2024
- Shortest Distance Between Two NodesONSITE INTERVIEW · Seen Jan 2024
- Fit Beta Parameters by Maximum LikelihoodONSITE INTERVIEW · Seen Sep 2022
Similar questions at other companies
- Explore an Unknown Grid and Find a PathLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Rectangle Point Coverage CountsOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Spiral MatrixNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
- Tic-Tac-Toe Move WinnersByteDance · ONSITE INTERVIEWByteDance interview questions
- Trace Every Water Drop to Its Resting DestinationGoogle · ONSITE INTERVIEWGoogle interview questions
- Stochastic Gradient Descent with MomentumMeta · ONSITE INTERVIEWMeta interview questions
- Cyclic Fuel Command SimulationWaymo · ONSITE INTERVIEWWaymo interview questions
- Generate a Spiral MatrixMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Minesweeper Board UpdateUber · ONSITE INTERVIEWUber interview questions
- Spiral Matrix with ObstaclesTemu · ONSITE INTERVIEWTemu interview questions