Matrix / 2D Arrays Interview Questions [2026-2027]
174+ real questions from verified interview reports across 12 companies.
Sourced from 1Point3Acres, Blind, Glassdoor, Reddit, and more. Translated and cleaned.
Top Companies Asking Matrix / 2D Arrays Questions
Sample Matrix / 2D Arrays Questions
There were 2 questions in the PS round: Q1: https://leetcode.com/problems/largest-submatrix-with-rearrangements/ I was able to think about the prefix height at every row but was confused about how to maximize by rearranging. However,...
Google | Warsaw | SWE 2/3 | Offer
Hi all, I recently gave Google interviews for Warsaw location for software engineer 2/3 (recruiter told me that they would consider me for both positions). ## Screening Question was related some...
The first round was with HM (Host Manager). We started by discussing my projects, mainly focusing on preparing for my most important project. The whole conversation went well, with no major issues. Th
Recruiter reached out in September for a opening. HM didnt shortlist resume back then. Again reached out to recruiter in November and then in December, she shared another opening and got me the interv
3 hours is more than enough for 4 questions. C++ or Csharp must be used. 1- Given a square matrix with values representing pixel colors black and white, implement a function that finds the largest sub
1. Given 2D nodes with w and b, find the maximum square when all sides are 'b'. 2. In a BST, find the number of edges between 2 given nodes. 3. Given Arr1 and Arr2, return the maximum element in Arr1'
**Context** Doppel, a Series B startup focused on detecting and mitigating social engineering attacks, utilizes the following multi-stage technical problem during their interview process. **Problem St
**Problem Statement** Develop a program that renders an ASCII graph to visualize online auction data, where the X-axis represents time and the Y-axis represents price. **Input Specifications** * **Dat
Chegg Interview Experience for SDE FTE (On-Campus)
Round 1: Round one had only 3 coding questions which were pretty easy.Decimal Equivalent of Binary Linked List.Detecting loop in the linked list.Generate all the binary st...
You and your friend go to a game arcade where you choose to play the game Lucky Pick. In the game, there is a square grid and on each block,...
Round 1:My round 1 was not that hard, it was resume based session, it started with my introduction and then i was asked about encapsulation, since my project was android b...
#54 Spiral Matrix
LeetCode #54: Spiral Matrix. Difficulty: Medium. Topics: Array, Matrix, Simulation. Asked at PhonePe in the last 6 months.
#73 Set Matrix Zeroes
LeetCode #73: Set Matrix Zeroes. Difficulty: Medium. Topics: Array, Hash Table, Matrix. Asked at ZScaler in the last 6 months.
LeetCode #1559: Detect Cycles in 2D Grid. Difficulty: Medium. Topics: Array, Depth-First Search, Breadth-First Search, Union-Find, Matrix. Asked at WeRide in the last 6 months.
#73 Set Matrix Zeroes
LeetCode #73: Set Matrix Zeroes. Difficulty: Medium. Topics: Array, Hash Table, Matrix. Asked at Nykaa in the last 6 months.
LeetCode #1162: As Far from Land as Possible. Difficulty: Medium. Topics: Array, Dynamic Programming, Breadth-First Search, Matrix. Asked at Hive in the last 6 months.
## Problem A grid of colored bubbles is represented as a 2D array of characters. When a player pops a bubble at `(r, c)`, all connected bubbles of the same color (4-directional flood fill) are removed. Remaining bubbles above the removed region fall down to fill the gap (gravity: bubbles fall straight down, not diagonally). Simulate a sequence of pops and return the grid state after all pops. ```python def simulate_pops(grid: list[list[str]], pops: list[tuple[int,int]]) -> list[list[str]]: # '.' represents empty space ... ``` **Example:** ``` grid = [ ['R','B','R'], ['R','B','B'], ['G','G','B'] ] pops = [(0,0)] # pop 'R' at (0,0), connected R's: (0,0),(1,0) After flood fill remove: [['.',B','R'], ['.','B','B'], ['G','G','B']] After gravity: [['.','B','R'], ['G','B','B'], ['.','G','B']] ``` ## Follow-ups - What is the time complexity per pop operation? - How do you handle chain reactions (removed bubbles expose new connected groups of size >= 3 that auto-pop)? - Extend to 3D (cube grid) -- how does gravity change?
## Problem A game field is an `N x M` grid. Each cell is either empty (`0`) or contains a power-up (`1`). A player starts at `(0, 0)` and must reach `(N-1, M-1)` moving only right or down. The player collects all power-ups on their path. **Part 1:** Find the path that collects the maximum number of power-ups. **Part 2:** After collecting power-ups along the optimal path, those cells become `0`. Find the maximum power-ups collectible on a second independent path from `(0,0)` to `(N-1,M-1)` on the modified grid. ```python def max_powerups_two_paths(grid: list[list[int]]) -> int: ... ``` **Example:** ``` grid = [[1,1,0],[0,1,1],[0,0,1]] Path 1: (0,0)->(0,1)->(1,1)->(1,2)->(2,2) collects 5. Modified grid: all zeros. Path 2: 0. Total: 5 ``` ## Follow-ups - Can you solve Part 2 by running two simultaneous paths via DP? What are the DP states? - What if movement includes up and left (any direction, no revisit)? How does the complexity change? - Extend to `k` paths. What is the DP formulation?
## Problem Given an `N x M` matrix of non-negative integers, partition it into exactly `k` non-overlapping horizontal strips (contiguous row groups). The cost of a strip is the sum of all elements in it. Minimize the maximum strip cost. ```python def min_max_strip_cost(matrix: list[list[int]], k: int) -> int: ... ``` **Example:** ``` matrix = [[1,2],[3,4],[5,6]], k = 2 Strip options: [row0] + [row1,row2]: max(3, 18) = 18 [row0,row1] + [row2]: max(10, 11) = 11 Output: 11 ``` ## Approach Binary search on the answer: for a given max cost `mid`, greedily check if the matrix can be partitioned into at most `k` strips where each strip sum <= `mid`. Precompute row sums. ## Follow-ups - What is the time complexity of the binary search + greedy check approach? - Extend to vertical strips (column groups) -- does the greedy check still work in O(M) per candidate cost? - How does the problem change if strips must have equal numbers of rows (i.e., `N` must be divisible by `k`)?
## Problem Design a `RectangleFitter` that tracks a set of axis-aligned rectangles and answers fitting queries. ```python class RectangleFitter: def add_rect(self, rect_id: str, w: int, h: int) -> None: ... def remove_rect(self, rect_id: str) -> None: ... def fits_in(self, W: int, H: int) -> list[str]: # Return all rect_ids where w <= W and h <= H, sorted by area desc ... def largest_fitting(self, W: int, H: int) -> str | None: # Return rect_id with largest area that fits in W x H container ... def count_fitting(self, W: int, H: int) -> int: ... ``` **Example:** ``` rf = RectangleFitter() rf.add_rect("A", 3, 4) # area 12 rf.add_rect("B", 5, 2) # area 10 rf.add_rect("C", 2, 2) # area 4 rf.fits_in(4, 4) -> ["A", "C"] # B: 5>4 fails rf.largest_fitting(4,4) -> "A" rf.count_fitting(2,2) -> 1 ``` ## Follow-ups - For `fits_in` with n rectangles and q queries, can you preprocess to answer each query in sub-O(n) time? - What 2D data structure (e.g., fractional cascading, 2D segment tree) could help here? - Extend to rotatable rectangles: a rect `(w, h)` fits if `(w<=W and h<=H) or (h<=W and w<=H)`.
## Problem Simulate a robot following movement commands on a grid and determine its final position. ## Tags matrix, arrays
## Round 1 - Coding (Frontend) ## Problem Implement the selection logic for a spreadsheet grid. Support: - `select_cell(row, col)` — single cell selection, clears previous. - `extend_selection(row, col)` — extend selection from anchor to `(row, col)` (shift+click behavior). - `toggle_cell(row, col)` — add/remove a cell from selection (ctrl+click). - `get_selected_cells() -> set[tuple[int,int]]` — return all currently selected cells. - `get_selection_bounds() -> tuple[int,int,int,int]` — return `(min_row, min_col, max_row, max_col)` of selection. ```python class TableSelection: def select_cell(self, row: int, col: int) -> None: ... def extend_selection(self, row: int, col: int) -> None: ... def toggle_cell(self, row: int, col: int) -> None: ... def get_selected_cells(self) -> set[tuple[int,int]]: ... ``` ``` select_cell(0,0) # selected: {(0,0)}, anchor=(0,0) extend_selection(2,2) # selected: full 3x3 block (0,0)-(2,2) toggle_cell(1,1) # deselect center; selected: 8 border cells get_selection_bounds() # -> (0,0,2,2) ``` ## Follow-ups 1. `extend_selection` fills a rectangular block. How do you enumerate all cells in that block efficiently? 2. How does keyboard navigation (arrow keys + shift) map to your API? 3. What if the grid has 1 million rows? How do you represent a large contiguous selection without storing every cell? 4. Describe how you would serialize the selection state for copy-paste operations.
## Problem Simulate a battleship-style sea battle game on a grid, detecting hits and misses or computing game state after a sequence of moves. ## Likely LeetCode equivalent No direct match. ## Tags matrix, simulation, coding, oa
## Problem You are given a 2D grid representing an ancient tomb. Each cell is one of: - `'.'` — open path - `'#'` — wall - `'T'` — trap (costs 2 moves to pass through) - `'G'` — gold (must be collected on the way) Find the minimum-cost path from the top-left `(0,0)` to the bottom-right `(n-1, m-1)` that collects **all** gold cells. Return -1 if no such path exists. ```python def min_cost_tomb(grid: list[list[str]]) -> int: pass ``` ## Example ``` Input: grid = [ ['.', 'G', '#'], ['.', 'T', '.'], ['.', '.', 'G'] ] Output: 5 # path: (0,0)->(1,0)->(2,0)->(2,1)->(1,1)[trap,+2]->(0,1)[gold]->(1,1)->(2,1)->(2,2)[gold] # Note: must revisit to collect all gold ``` ## Follow-ups 1. What if gold has individual point values and you want to maximize score within a move budget? 2. How does the complexity change as the number of gold cells grows? What is the tightest bound? 3. Can you optimize for the case where gold cells are sparse (fewer than 10)? 4. How would you extend this to a 3D tomb (x, y, z coordinates)?
See All 174 Matrix / 2D Arrays Questions
Full question text, interview context, and company-specific frequency data for subscribers.
Get Access