array matrix Pattern
48 problems
Pattern pages help build reusable solving frames. Identify signals first, then explain state, transition, and edge handling.
Recognition Signals
- Do you understand the process of adjusting boundaries dynamically in a spiral traversal?
- Can you explain how the simulation approach helps to cover all matrix elements in spiral order?
- The candidate demonstrates an understanding of array traversal techniques.
Solve Flow
- 1. Define the active state/window.
- 2. Update state while preserving invariants.
- 3. Validate with edge-heavy examples.
Common Misses
- Not adjusting the boundaries after each pass (top, bottom, left, right) will cause revisiting the same elements.
- Forgetting to adjust the boundaries after completing a row or column, causing an infinite loop or overwriting cells.
- Updating cells in a single pass without markers causes neighbor counts to be incorrect.
Recommended Ladder
Spiral Matrix
Given an m x n matrix, return all elements in spiral order starting from the top-left corner.
Spiral Matrix II
Generate a spiral matrix of size n x n, filled with elements from 1 to n² in spiral order, for interview-focused solving…
Game of Life
Solve the Game of Life by updating each cell based on its eight neighbors using Array and Matrix simulation patterns eff…
Diagonal Traverse
Traverse a matrix diagonally and return all elements in the specific zig-zag order required by the problem pattern.
Reshape the Matrix
Reshape the Matrix involves transforming a 2D matrix into a new matrix with the same elements in row-major order, follow…
Image Smoother
Apply a 3x3 smoothing filter to a matrix, rounding down each cell average including surrounding neighbors for accurate r…
Toeplitz Matrix
Determine if a given matrix is a Toeplitz matrix by checking diagonal consistency.
Valid Tic-Tac-Toe State
Verify if a given Tic-Tac-Toe board can represent a valid game state during a valid sequence of moves.
Image Overlap
Image Overlap requires calculating the overlap between two binary matrices by translating one image over the other.
Transpose Matrix
Transpose Matrix problem requires flipping a matrix's rows and columns to return the transposed version.
Spiral Matrix III
Solve the Spiral Matrix III problem by simulating the movement across a matrix with specific constraints on direction an…
Available Captures for Rook
This problem involves finding the number of pawns a rook can capture on a chessboard, considering obstacles like bishops…
Queens That Can Attack the King
Identify all black queens on an 8x8 chessboard that can attack the white king using array and matrix simulation techniqu…
Shift 2D Grid
Shift 2D Grid requires shifting elements of a matrix by a given number of times, simulating step-by-step movement.
Matrix Block Sum
Compute a matrix where each cell contains the sum of all elements within k-distance blocks using prefix sums efficiently…
Lucky Numbers in a Matrix
The Lucky Numbers in a Matrix problem involves finding elements that are the minimum in their row and maximum in their c…
Matrix Diagonal Sum
Calculate the sum of both primary and secondary diagonals in a square matrix while avoiding double-counting overlaps.
Special Positions in a Binary Matrix
Identify all special positions in a binary matrix where a 1 has no other 1s in its row or column, ensuring optimal array…
Richest Customer Wealth
Calculate the richest customer's wealth by summing the amounts in each customer's bank accounts in a matrix.
Where Will the Ball Fall
Determine where each ball exits a diagonal board grid or if it gets stuck, using matrix simulation with careful traversa…
Determine Whether Matrix Can Be Obtained By Rotation
Determine if a binary matrix can be transformed into another by rotating it 90 degrees multiple times.
Largest Magic Square
Find the side length of the largest magic square in a matrix where row, column, and diagonal sums are equal.
Cyclically Rotating a Grid
This problem requires cyclically rotating a grid by rotating each layer of the matrix counter-clockwise for a specified …
Check if Move is Legal
Determine if a move on an 8x8 board is legal by validating lines in all directions using array and matrix patterns.
Grid Game
Solve the Grid Game problem by optimizing the movement of two robots on a 2D matrix grid.
Check if Word Can Be Placed In Crossword
Determine if a word fits in a crossword grid using array and matrix checks, accounting for spaces, letters, and blocked …
Convert 1D Array Into 2D Array
Convert a 1D integer array into a structured 2D array with specified rows and columns using all elements sequentially.
Maximum Trailing Zeros in a Cornered Path
Find the maximum trailing zeros in the product of a cornered path within a 2D grid.
Count Unguarded Cells in the Grid
Solve Count Unguarded Cells in the Grid by marking guard sight lines across a blocked matrix and counting untouched empt…
Check if Matrix Is X-Matrix
Check if a square matrix follows the X-Matrix pattern by validating diagonal and non-diagonal conditions.
Largest Local Values in a Matrix
Find the largest value in every 3x3 submatrix of an n x n integer matrix efficiently using nested loops.
Maximum Sum of an Hourglass
Calculate the maximum sum of an hourglass in a 2D matrix using array traversal and submatrix evaluation techniques effic…
Difference Between Ones and Zeros in Row and Column
This problem requires computing a difference matrix based on the ones and zeros in each row and column of a binary matri…
Increment Submatrices by One
Increment Submatrices by One focuses on efficiently updating submatrices using row-wise prefix sums in an n by n matrix.
Find the Width of Columns of a Grid
This problem asks you to compute the width of each column in a grid, where the width is defined by the length of the lar…
Row With Maximum Ones
Find the row with the maximum ones in a binary matrix and return its index and count.
Construct Product Matrix
Solve the "Construct Product Matrix" problem by calculating the product of elements in 2D matrices without division.
Find Champion I
Find Champion I is an easy problem focusing on identifying the strongest team in a tournament using matrix-based compari…
Find the Grid of Region Average
Find the Grid of Region Average requires identifying regions in a matrix where pixel differences are below a threshold, …
Modify the Matrix
Modify the Matrix efficiently by replacing all -1 elements with the maximum in their column using array and matrix opera…
Count Submatrices with Top-Left Element and Sum Less Than k
Count all submatrices including the top-left element with sum less than k using array and matrix prefix sum strategies.
Make a Square with the Same Color
Determine if a 3x3 grid can form a 2x2 square of the same color by changing at most one cell efficiently.
Check if Grid Satisfies Conditions
Check if a grid satisfies given conditions by analyzing array and matrix structure with specific checks on values.
Find the Minimum Area to Cover All Ones I
Find the smallest rectangle to cover all 1's in a 2D binary matrix, focusing on array and matrix handling.
Find the Minimum Area to Cover All Ones II
Find the minimum area to cover all 1's in a 2D binary grid using three non-overlapping rectangles.
Count Submatrices With Equal Frequency of X and Y
Count the number of submatrices with equal frequency of 'X' and 'Y' in a 2D character grid.
Zigzag Grid Traversal With Skip
Traverse a 2D grid in a zigzag pattern while skipping alternate cells, focusing on array and matrix manipulation challen…
Equal Sum Grid Partition I
Determine if an m x n matrix grid can be split into two non-empty sections with equal sums by making a single horizontal…