LeetCodechevron_rightSolve patternschevron_rightarray matrix
schemaReusable solving pattern

array matrix Pattern

Pattern hubs are for building transferable solving frames. Learn the recognition signals first, then drill state definition, update rules, and edge explanation until the pattern feels stable.

database48 problemstune21/26/1 difficulty mixcategory4 linked topics

Pattern brief

Recognize first

Do you understand the process of adjusting boundaries dynamically in a spiral traversal?

Solve rhythm

State the active state and invariant first, explain how each update preserves them, then pressure-test with counterexamples.

Most common miss

Not adjusting the boundaries after each pass (top, bottom, left, right) will cause revisiting the same elements.

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

Problem bank

array matrix pattern bank

Start by scanning with search or difficulty filters, then narrow by linked topics. The bank continues loading inside its own container so the page stays readable.

Progressive pattern bank

Use it to build pattern understanding first, then expand into the full corpus.

hourglass_bottomScroll inside to continue
search
tuneDifficulty
categoryTopic focus

Showing 24 / 48 problems

+24 per load
#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

swap_vertScroll inside the bank to auto-load more

Continue by topic

Once the pattern itself feels familiar, move back into concrete topic hubs so you can separate the pattern from the changing problem context.

route

Guided Practice Path

AI recommends problems by your level and tracks your progress.

Start Guided Patharrow_forward
Array plus Matrix LeetCode Pattern: 48 Solutions