LeetCodechevron_rightarray matrix

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. 1. Define the active state/window.
  2. 2. Update state while preserving invariants.
  3. 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

#TitleDifficulty
54

Spiral Matrix

Given an m x n matrix, return all elements in spiral order starting from the top-left corner.

Medium
59

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…

Medium
289

Game of Life

Solve the Game of Life by updating each cell based on its eight neighbors using Array and Matrix simulation patterns eff…

Medium
498

Diagonal Traverse

Traverse a matrix diagonally and return all elements in the specific zig-zag order required by the problem pattern.

Medium
566

Reshape the Matrix

Reshape the Matrix involves transforming a 2D matrix into a new matrix with the same elements in row-major order, follow…

Easy
661

Image Smoother

Apply a 3x3 smoothing filter to a matrix, rounding down each cell average including surrounding neighbors for accurate r…

Easy
766

Toeplitz Matrix

Determine if a given matrix is a Toeplitz matrix by checking diagonal consistency.

Easy
794

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.

Medium
835

Image Overlap

Image Overlap requires calculating the overlap between two binary matrices by translating one image over the other.

Medium
867

Transpose Matrix

Transpose Matrix problem requires flipping a matrix's rows and columns to return the transposed version.

Easy
885

Spiral Matrix III

Solve the Spiral Matrix III problem by simulating the movement across a matrix with specific constraints on direction an…

Medium
999

Available Captures for Rook

This problem involves finding the number of pawns a rook can capture on a chessboard, considering obstacles like bishops…

Easy
1222

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…

Medium
1260

Shift 2D Grid

Shift 2D Grid requires shifting elements of a matrix by a given number of times, simulating step-by-step movement.

Easy
1314

Matrix Block Sum

Compute a matrix where each cell contains the sum of all elements within k-distance blocks using prefix sums efficiently…

Medium
1380

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…

Easy
1572

Matrix Diagonal Sum

Calculate the sum of both primary and secondary diagonals in a square matrix while avoiding double-counting overlaps.

Easy
1582

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…

Easy
1672

Richest Customer Wealth

Calculate the richest customer's wealth by summing the amounts in each customer's bank accounts in a matrix.

Easy
1706

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…

Medium
1886

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.

Easy
1895

Largest Magic Square

Find the side length of the largest magic square in a matrix where row, column, and diagonal sums are equal.

Medium
1914

Cyclically Rotating a Grid

This problem requires cyclically rotating a grid by rotating each layer of the matrix counter-clockwise for a specified …

Medium
1958

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.

Medium
2017

Grid Game

Solve the Grid Game problem by optimizing the movement of two robots on a 2D matrix grid.

Medium
2018

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 …

Medium
2022

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.

Easy
2245

Maximum Trailing Zeros in a Cornered Path

Find the maximum trailing zeros in the product of a cornered path within a 2D grid.

Medium
2257

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…

Medium
2319

Check if Matrix Is X-Matrix

Check if a square matrix follows the X-Matrix pattern by validating diagonal and non-diagonal conditions.

Easy
2373

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.

Easy
2428

Maximum Sum of an Hourglass

Calculate the maximum sum of an hourglass in a 2D matrix using array traversal and submatrix evaluation techniques effic…

Medium
2482

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…

Medium
2536

Increment Submatrices by One

Increment Submatrices by One focuses on efficiently updating submatrices using row-wise prefix sums in an n by n matrix.

Medium
2639

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…

Easy
2643

Row With Maximum Ones

Find the row with the maximum ones in a binary matrix and return its index and count.

Easy
2906

Construct Product Matrix

Solve the "Construct Product Matrix" problem by calculating the product of elements in 2D matrices without division.

Medium
2923

Find Champion I

Find Champion I is an easy problem focusing on identifying the strongest team in a tournament using matrix-based compari…

Easy
3030

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, …

Medium
3033

Modify the Matrix

Modify the Matrix efficiently by replacing all -1 elements with the maximum in their column using array and matrix opera…

Easy
3070

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.

Medium
3127

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.

Easy
3142

Check if Grid Satisfies Conditions

Check if a grid satisfies given conditions by analyzing array and matrix structure with specific checks on values.

Easy
3195

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.

Medium
3197

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.

Hard
3212

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.

Medium
3417

Zigzag Grid Traversal With Skip

Traverse a 2D grid in a zigzag pattern while skipping alternate cells, focusing on array and matrix manipulation challen…

Easy
3546

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…

Medium

Related Topics

Array plus Matrix LeetCode Pattern: 48 Solutions