Matrix Problems

Master matrix problems with AI-powered solutions. Get instant coding assistance during your technical interviews for all 168 problems in this category.

Total Problems: 168
Easy: 34
Medium: 93
Hard: 41
Showing 50 of 168 problems

Problems

Scroll within this area to browse all problems

#
Title
Difficulty
200

Number of Islands

Medium
54

Spiral Matrix

Medium
79

Word Search

Medium
48

Rotate Image

Medium
733

Flood Fill

Easy
898

Transpose Matrix

Easy
378

Kth Smallest Element in a Sorted Matrix

Medium
289

Game of Life

Medium
529

Minesweeper

Medium
212

Word Search II

Hard
1036

Rotting Oranges

Medium
36

Valid Sudoku

Medium
945

Snakes and Ladders

Medium
787

Sliding Puzzle

Hard
741

Cherry Pickup

Hard
329

Longest Increasing Path in a Matrix

Hard
37

Sudoku Solver

Hard
2047

Find a Peak Element II

Medium
854

Making A Large Island

Hard
794

Swim in Rising Water

Hard
777

Toeplitz Matrix

Easy
74

Search a 2D Matrix

Medium
542

01 Matrix

Medium
63

Unique Paths II

Medium
73

Set Matrix Zeroes

Medium
417

Pacific Atlantic Water Flow

Medium
1559

Cherry Pickup II

Hard
174

Dungeon Game

Hard
1414

Shortest Path in a Grid with Obstacles Elimination

Hard
1171

Shortest Path in Binary Matrix

Medium
64

Minimum Path Sum

Medium
861

Flipping an Image

Easy
3188

Find Champion I

Easy
2035

Count Sub Islands

Medium
59

Spiral Matrix II

Medium
971

Shortest Bridge

Medium
928

Surface Area of 3D Shapes

Easy
1380

Number of Closed Islands

Medium
2038

Nearest Exit from Entrance in Maze

Medium
3823

Count Islands With Total Value Divisible by K

Medium
221

Maximal Square

Medium
2411

Spiral Matrix IV

Medium
407

Trapping Rain Water II

Hard
921

Spiral Matrix III

Medium
695

Max Area of Island

Medium
240

Search a 2D Matrix II

Medium
130

Surrounded Regions

Medium
1402

Count Square Submatrices with All Ones

Medium
661

Image Smoother

Easy
419

Battleships in a Board

Medium
Loading more problems...

Matrix LeetCode Problems List

  • 200. Number of Islands - Medium - MatrixGiven an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands. An island is surrounded by wa... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
  • 54. Spiral Matrix - Medium - MatrixGiven an m x n matrix, return all elements of the matrix in spiral order.... Topics: Array, Matrix, Simulation
  • 79. Word Search - Medium - MatrixGiven an m x n grid of characters board and a string word, return true if word exists in the grid. The word can be constructed from letters of sequent... Topics: Array, String, Backtracking, Depth-First Search, Matrix
  • 48. Rotate Image - Medium - MatrixYou are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise). You have to rotate the image in-place, which means... Topics: Array, Math, Matrix
  • 733. Flood Fill - Easy - MatrixYou are given an image represented by an m x n grid of integers image, where image[i][j] represents the pixel value of the image. You are also given t... Topics: Array, Depth-First Search, Breadth-First Search, Matrix
  • 898. Transpose Matrix - Easy - MatrixGiven a 2D integer array matrix, return the transpose of matrix. The transpose of a matrix is the matrix flipped over its main diagonal, switching the... Topics: Array, Matrix, Simulation
  • 378. Kth Smallest Element in a Sorted Matrix - Medium - MatrixGiven an n x n matrix where each of the rows and columns is sorted in ascending order, return the kth smallest element in the matrix. Note that it is ... Topics: Array, Binary Search, Sorting, Heap (Priority Queue), Matrix
  • 289. Game of Life - Medium - MatrixAccording to Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Hort... Topics: Array, Matrix, Simulation
  • 529. Minesweeper - Medium - MatrixLet's play the minesweeper game (Wikipedia, online game)! You are given an m x n char matrix board representing the game board where: 'M' represents a... Topics: Array, Depth-First Search, Breadth-First Search, Matrix
  • 212. Word Search II - Hard - MatrixGiven an m x n board of characters and a list of strings words, return all words on the board. Each word must be constructed from letters of sequentia... Topics: Array, String, Backtracking, Trie, Matrix
  • 1036. Rotting Oranges - Medium - MatrixYou are given an m x n grid where each cell can have one of three values: 0 representing an empty cell, 1 representing a fresh orange, or 2 representi... Topics: Array, Breadth-First Search, Matrix
  • 36. Valid Sudoku - Medium - MatrixDetermine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: Each row must contain the dig... Topics: Array, Hash Table, Matrix
  • 945. Snakes and Ladders - Medium - MatrixYou are given an n x n integer matrix board where the cells are labeled from 1 to n2 in a Boustrophedon style starting from the bottom left of the boa... Topics: Array, Breadth-First Search, Matrix
  • 787. Sliding Puzzle - Hard - MatrixOn an 2 x 3 board, there are five tiles labeled from 1 to 5, and an empty square represented by 0. A move consists of choosing 0 and a 4-directionally... Topics: Array, Dynamic Programming, Backtracking, Breadth-First Search, Memoization, Matrix
  • 741. Cherry Pickup - Hard - MatrixYou are given an n x n grid representing a field of cherries, each cell is one of three possible integers. 0 means the cell is empty, so you can pass ... Topics: Array, Dynamic Programming, Matrix
  • 329. Longest Increasing Path in a Matrix - Hard - MatrixGiven an m x n integers matrix, return the length of the longest increasing path in matrix. From each cell, you can either move in four directions: le... Topics: Array, Dynamic Programming, Depth-First Search, Breadth-First Search, Graph, Topological Sort, Memoization, Matrix
  • 37. Sudoku Solver - Hard - MatrixWrite a program to solve a Sudoku puzzle by filling the empty cells. A sudoku solution must satisfy all of the following rules: Each of the digits 1-9... Topics: Array, Hash Table, Backtracking, Matrix
  • 2047. Find a Peak Element II - Medium - MatrixA peak element in a 2D grid is an element that is strictly greater than all of its adjacent neighbors to the left, right, top, and bottom. Given a 0-i... Topics: Array, Binary Search, Matrix
  • 854. Making A Large Island - Hard - MatrixYou are given an n x n binary matrix grid. You are allowed to change at most one 0 to be 1. Return the size of the largest island in grid after applyi... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
  • 794. Swim in Rising Water - Hard - MatrixYou are given an n x n integer matrix grid where each value grid[i][j] represents the elevation at that point (i, j). It starts raining, and water gra... Topics: Array, Binary Search, Depth-First Search, Breadth-First Search, Union Find, Heap (Priority Queue), Matrix
  • 777. Toeplitz Matrix - Easy - MatrixGiven an m x n matrix, return true if the matrix is Toeplitz. Otherwise, return false. A matrix is Toeplitz if every diagonal from top-left to bottom-... Topics: Array, Matrix
  • 74. Search a 2D Matrix - Medium - MatrixYou are given an m x n integer matrix matrix with the following two properties: Each row is sorted in non-decreasing order. The first integer of each ... Topics: Array, Binary Search, Matrix
  • 542. 01 Matrix - Medium - MatrixGiven an m x n binary matrix mat, return the distance of the nearest 0 for each cell. The distance between two cells sharing a common edge is 1.... Topics: Array, Dynamic Programming, Breadth-First Search, Matrix
  • 63. Unique Paths II - Medium - MatrixYou are given an m x n integer array grid. There is a robot initially located at the top-left corner (i.e., grid[0][0]). The robot tries to move to th... Topics: Array, Dynamic Programming, Matrix
  • 73. Set Matrix Zeroes - Medium - MatrixGiven an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's. You must do it in place.... Topics: Array, Hash Table, Matrix
  • 417. Pacific Atlantic Water Flow - Medium - MatrixThere is an m x n rectangular island that borders both the Pacific Ocean and Atlantic Ocean. The Pacific Ocean touches the island's left and top edges... Topics: Array, Depth-First Search, Breadth-First Search, Matrix
  • 1559. Cherry Pickup II - Hard - MatrixYou are given a rows x cols matrix grid representing a field of cherries where grid[i][j] represents the number of cherries that you can collect from ... Topics: Array, Dynamic Programming, Matrix
  • 174. Dungeon Game - Hard - MatrixThe demons had captured the princess and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of m x n rooms laid out in a 2D ... Topics: Array, Dynamic Programming, Matrix
  • 1414. Shortest Path in a Grid with Obstacles Elimination - Hard - MatrixYou are given an m x n integer matrix grid where each cell is either 0 (empty) or 1 (obstacle). You can move up, down, left, or right from and to an e... Topics: Array, Breadth-First Search, Matrix
  • 1171. Shortest Path in Binary Matrix - Medium - MatrixGiven an n x n binary matrix grid, return the length of the shortest clear path in the matrix. If there is no clear path, return -1. A clear path in a... Topics: Array, Breadth-First Search, Matrix
  • 64. Minimum Path Sum - Medium - MatrixGiven a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.... Topics: Array, Dynamic Programming, Matrix
  • 861. Flipping an Image - Easy - MatrixGiven an n x n binary matrix image, flip the image horizontally, then invert it, and return the resulting image. To flip an image horizontally means t... Topics: Array, Two Pointers, Bit Manipulation, Matrix, Simulation
  • 3188. Find Champion I - Easy - MatrixThere are n teams numbered from 0 to n - 1 in a tournament. Given a 0-indexed 2D boolean matrix grid of size n * n. For all i, j that 0 <= i, j <= n -... Topics: Array, Matrix
  • 2035. Count Sub Islands - Medium - MatrixYou are given two m x n binary matrices grid1 and grid2 containing only 0's (representing water) and 1's (representing land). An island is a group of ... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
  • 59. Spiral Matrix II - Medium - MatrixGiven a positive integer n, generate an n x n matrix filled with elements from 1 to n2 in spiral order.... Topics: Array, Matrix, Simulation
  • 971. Shortest Bridge - Medium - MatrixYou are given an n x n binary matrix grid where 1 represents land and 0 represents water. An island is a 4-directionally connected group of 1's not co... Topics: Array, Depth-First Search, Breadth-First Search, Matrix
  • 928. Surface Area of 3D Shapes - Easy - MatrixYou are given an n x n grid where you have placed some 1 x 1 x 1 cubes. Each value v = grid[i][j] represents a tower of v cubes placed on top of cell ... Topics: Array, Math, Geometry, Matrix
  • 1380. Number of Closed Islands - Medium - MatrixGiven a 2D grid consists of 0s (land) and 1s (water).  An island is a maximal 4-directionally connected group of 0s and a closed island is an island t... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
  • 2038. Nearest Exit from Entrance in Maze - Medium - MatrixYou are given an m x n matrix maze (0-indexed) with empty cells (represented as '.') and walls (represented as '+'). You are also given the entrance o... Topics: Array, Breadth-First Search, Matrix
  • 3823. Count Islands With Total Value Divisible by K - Medium - MatrixYou are given an m x n matrix grid and a positive integer k. An island is a group of positive integers (representing land) that are 4-directionally co... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
  • 221. Maximal Square - Medium - MatrixGiven an m x n binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.... Topics: Array, Dynamic Programming, Matrix
  • 2411. Spiral Matrix IV - Medium - MatrixYou are given two integers m and n, which represent the dimensions of a matrix. You are also given the head of a linked list of integers. Generate an ... Topics: Array, Linked List, Matrix, Simulation
  • 407. Trapping Rain Water II - Hard - MatrixGiven an m x n integer matrix heightMap representing the height of each unit cell in a 2D elevation map, return the volume of water it can trap after ... Topics: Array, Breadth-First Search, Heap (Priority Queue), Matrix
  • 921. Spiral Matrix III - Medium - MatrixYou start at the cell (rStart, cStart) of an rows x cols grid facing east. The northwest corner is at the first row and column in the grid, and the so... Topics: Array, Matrix, Simulation
  • 695. Max Area of Island - Medium - MatrixYou are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
  • 240. Search a 2D Matrix II - Medium - MatrixWrite an efficient algorithm that searches for a value target in an m x n integer matrix matrix. This matrix has the following properties: Integers in... Topics: Array, Binary Search, Divide and Conquer, Matrix
  • 130. Surrounded Regions - Medium - MatrixYou are given an m x n matrix board containing letters 'X' and 'O', capture regions that are surrounded: Connect: A cell is connected to adjacent cell... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
  • 1402. Count Square Submatrices with All Ones - Medium - MatrixGiven a m * n matrix of ones and zeros, return how many square submatrices have all ones.... Topics: Array, Dynamic Programming, Matrix
  • 661. Image Smoother - Easy - MatrixAn image smoother is a filter of the size 3 x 3 that can be applied to each cell of an image by rounding down the average of the cell and the eight su... Topics: Array, Matrix
  • 419. Battleships in a Board - Medium - MatrixGiven an m x n matrix board where each cell is a battleship 'X' or empty '.', return the number of the battleships on board. Battleships can only be p... Topics: Array, Depth-First Search, Matrix
  • 2428. Equal Row and Column Pairs - Medium - MatrixGiven a 0-indexed n x n integer matrix grid, return the number of pairs (ri, cj) such that row ri and column cj are equal. A row and column pair is co... Topics: Array, Hash Table, Matrix, Simulation
  • 870. Magic Squares In Grid - Medium - MatrixA 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each row, column, and both diagonals all have the same sum. Gi... Topics: Array, Hash Table, Math, Matrix
  • 1400. Find Winner on a Tic Tac Toe Game - Easy - MatrixTic-tac-toe is played by two players A and B on a 3 x 3 grid. The rules of Tic-Tac-Toe are: Players take turns placing characters into empty squares '... Topics: Array, Hash Table, Matrix, Simulation
  • 1663. Detect Cycles in 2D Grid - Medium - MatrixGiven a 2D array of characters grid of size m x n, you need to find if there exists any cycle consisting of the same value in grid. A cycle is a path ... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
  • 1022. Unique Paths III - Hard - MatrixYou are given an m x n integer array grid where grid[i][j] could be: 1 representing the starting square. There is exactly one starting square. 2 repre... Topics: Array, Backtracking, Bit Manipulation, Matrix
  • 2250. K Highest Ranked Items Within a Price Range - Medium - MatrixYou are given a 0-indexed 2D integer array grid of size m x n that represents a map of the items in a shop. The integers in the grid represent the fol... Topics: Array, Breadth-First Search, Sorting, Heap (Priority Queue), Matrix
  • 967. Minimum Falling Path Sum - Medium - MatrixGiven an n x n array of integers matrix, return the minimum sum of any falling path through matrix. A falling path starts at any element in the first ... Topics: Array, Dynamic Programming, Matrix
  • 3627. Find Minimum Time to Reach Last Room I - Medium - MatrixThere is a dungeon with n x m rooms arranged as a grid. You are given a 2D array moveTime of size n x m, where moveTime[i][j] represents the minimum t... Topics: Array, Graph, Heap (Priority Queue), Matrix, Shortest Path
  • 1753. Path With Minimum Effort - Medium - MatrixYou are a hiker preparing for an upcoming hike. You are given heights, a 2D array of size rows x columns, where heights[row][col] represents the heigh... Topics: Array, Binary Search, Depth-First Search, Breadth-First Search, Union Find, Heap (Priority Queue), Matrix
  • 1117. As Far from Land as Possible - Medium - MatrixGiven an n x n grid containing only values 0 and 1, where 0 represents water and 1 represents land, find a water cell such that its distance to the ne... Topics: Array, Dynamic Programming, Breadth-First Search, Matrix
  • 2015. Determine Whether Matrix Can Be Obtained By Rotation - Easy - MatrixGiven two n x n binary matrices mat and target, return true if it is possible to make mat equal to target by rotating mat in 90-degree increments, or ... Topics: Array, Matrix
  • 498. Diagonal Traverse - Medium - MatrixGiven an m x n matrix mat, return an array of all the elements of the array in a diagonal order.... Topics: Array, Matrix, Simulation
  • 2344. Escape the Spreading Fire - Hard - MatrixYou are given a 0-indexed 2D integer array grid of size m x n which represents a field. Each cell has one of three values: 0 represents grass, 1 repre... Topics: Array, Binary Search, Breadth-First Search, Matrix
  • 3797. Design Spreadsheet - Medium - MatrixA spreadsheet is a grid with 26 columns (labeled from 'A' to 'Z') and a given number of rows. Each cell in the spreadsheet can hold an integer value b... Topics: Array, Hash Table, String, Design, Matrix
  • 2662. Check Knight Tour Configuration - Medium - MatrixThere is a knight on an n x n chessboard. In a valid configuration, the knight starts at the top-left cell of the board and visits every cell on the b... Topics: Array, Depth-First Search, Breadth-First Search, Matrix, Simulation
  • 463. Island Perimeter - Easy - MatrixYou are given row x col grid representing a map where grid[i][j] = 1 represents land and grid[i][j] = 0 represents water. Grid cells are connected hor... Topics: Array, Depth-First Search, Breadth-First Search, Matrix
  • 864. Image Overlap - Medium - MatrixYou are given two images, img1 and img2, represented as binary, square matrices of size n x n. A binary matrix has only 0s and 1s as values. We transl... Topics: Array, Matrix
  • 1379. Reconstruct a 2-Row Binary Matrix - Medium - MatrixGiven the following details of a matrix with n columns and 2 rows : The matrix is a binary matrix, which means each element in the matrix can be 0 or ... Topics: Array, Greedy, Matrix
  • 2254. Check if Every Row and Column Contains All Numbers - Easy - MatrixAn n x n matrix is valid if every row and every column contains all the integers from 1 to n (inclusive). Given an n x n integer matrix matrix, return... Topics: Array, Hash Table, Matrix
  • 3227. Find Missing and Repeated Values - Easy - MatrixYou are given a 0-indexed 2D integer matrix grid of size n * n with values in the range [1, n2]. Each integer appears exactly once except a which appe... Topics: Array, Hash Table, Math, Matrix
  • 1972. Rotating the Box - Medium - MatrixYou are given an m x n matrix of characters boxGrid representing a side-view of a box. Each cell of the box is one of the following: A stone '#' A sta... Topics: Array, Two Pointers, Matrix
  • 2409. Number of Increasing Paths in a Grid - Hard - MatrixYou are given an m x n integer matrix grid, where you can move from a cell to any adjacent cell in all 4 directions. Return the number of strictly inc... Topics: Array, Dynamic Programming, Depth-First Search, Breadth-First Search, Graph, Topological Sort, Memoization, Matrix
  • 1253. Sort the Matrix Diagonally - Medium - MatrixA matrix diagonal is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direc... Topics: Array, Sorting, Matrix
  • 3708. Zigzag Grid Traversal With Skip - Easy - MatrixYou are given an m x n 2D array grid of positive integers. Your task is to traverse grid in a zigzag pattern while skipping every alternate cell. Zigz... Topics: Array, Matrix, Simulation
  • 566. Reshape the Matrix - Easy - MatrixIn MATLAB, there is a handy function called reshape which can reshape an m x n matrix into a new one with a different size r x c keeping its original ... Topics: Array, Matrix, Simulation
  • 3031. Construct Product Matrix - Medium - MatrixGiven a 0-indexed 2D integer matrix grid of size n * m, we define a 0-indexed 2D matrix p of size n * m as the product matrix of grid if the following... Topics: Array, Matrix, Prefix Sum
  • 1324. Where Will the Ball Fall - Medium - MatrixYou have a 2-D grid of size m x n representing a box, and you have n balls. The box is open on the top and bottom sides. Each cell in the box has a di... Topics: Array, Matrix, Simulation
  • 1628. Count Submatrices With All Ones - Medium - MatrixGiven an m x n binary matrix mat, return the number of submatrices that have all ones.... Topics: Array, Dynamic Programming, Stack, Matrix, Monotonic Stack
  • 2067. Maximum Number of Points with Cost - Medium - MatrixYou are given an m x n integer matrix points (0-indexed). Starting with 0 points, you want to maximize the number of points you can get from the matri... Topics: Array, Dynamic Programming, Matrix
  • 1677. Matrix Diagonal Sum - Easy - MatrixGiven a square matrix mat, return the sum of the matrix diagonals. Only include the sum of all the elements on the primary diagonal and all the elemen... Topics: Array, Matrix
  • 1876. Map of Highest Peak - Medium - MatrixYou are given an integer matrix isWater of size m x n that represents a map of land and water cells. If isWater[i][j] == 0, cell (i, j) is a land cell... Topics: Array, Breadth-First Search, Matrix
  • 2521. Paths in Matrix Whose Sum Is Divisible by K - Hard - MatrixYou are given a 0-indexed m x n integer matrix grid and an integer k. You are currently at position (0, 0) and you want to reach position (m - 1, n - ... Topics: Array, Dynamic Programming, Matrix
  • 1711. Find Valid Matrix Given Row and Column Sums - Medium - MatrixYou are given two arrays rowSum and colSum of non-negative integers where rowSum[i] is the sum of the elements in the ith row and colSum[j] is the sum... Topics: Array, Greedy, Matrix
  • 810. Valid Tic-Tac-Toe State - Medium - MatrixGiven a Tic-Tac-Toe board as a string array board, return true if and only if it is possible to reach this board position during the course of a valid... Topics: Array, Matrix
  • 1224. Minimum Falling Path Sum II - Hard - MatrixGiven an n x n integer matrix grid, return the minimum sum of a falling path with non-zero shifts. A falling path with non-zero shifts is a choice of ... Topics: Array, Dynamic Programming, Matrix
  • 891. Score After Flipping Matrix - Medium - MatrixYou are given an m x n binary matrix grid. A move consists of choosing any row or column and toggling each value in that row or column (i.e., changing... Topics: Array, Greedy, Bit Manipulation, Matrix
  • 2103. Find All Groups of Farmland - Medium - MatrixYou are given a 0-indexed m x n binary matrix land where a 0 represents a hectare of forested land and a 1 represents a hectare of farmland. To keep t... Topics: Array, Depth-First Search, Breadth-First Search, Matrix
  • 1496. Lucky Numbers in a Matrix - Easy - MatrixGiven an m x n matrix of distinct numbers, return all lucky numbers in the matrix in any order. A lucky number is an element of the matrix such that i... Topics: Array, Matrix
  • 1555. Number of Ways of Cutting a Pizza - Hard - MatrixGiven a rectangular pizza represented as a rows x cols matrix containing the following characters: 'A' (an apple) and '.' (empty cell) and given the i... Topics: Array, Dynamic Programming, Memoization, Matrix, Prefix Sum
  • 2606. Difference Between Ones and Zeros in Row and Column - Medium - MatrixYou are given a 0-indexed m x n binary matrix grid. A 0-indexed m x n difference matrix diff is created with the following procedure: Let the number o... Topics: Array, Matrix, Simulation
  • 1342. Queens That Can Attack the King - Medium - MatrixOn a 0-indexed 8 x 8 chessboard, there can be multiple black queens and one white king. You are given a 2D integer array queens where queens[i] = [xQu... Topics: Array, Matrix, Simulation
  • 2472. Build a Matrix With Conditions - Hard - MatrixYou are given a positive integer k. You are also given: a 2D integer array rowConditions of size n where rowConditions[i] = [abovei, belowi], and a 2D... Topics: Array, Graph, Topological Sort, Matrix
  • 772. Construct Quad Tree - Medium - MatrixGiven a n * n matrix grid of 0's and 1's only. We want to represent grid with a Quad-Tree. Return the root of the Quad-Tree representing grid. A Quad-... Topics: Array, Divide and Conquer, Tree, Matrix
  • 2145. Grid Game - Medium - MatrixYou are given a 0-indexed 2D array grid of size 2 x n, where grid[r][c] represents the number of points at position (r, c) on the matrix. Two robots a... Topics: Array, Matrix, Prefix Sum
  • 2454. Largest Local Values in a Matrix - Easy - MatrixYou are given an n x n integer matrix grid. Generate an integer matrix maxLocal of size (n - 2) x (n - 2) such that: maxLocal[i][j] is equal to the la... Topics: Array, Matrix
  • 1471. Maximum Students Taking Exam - Hard - MatrixGiven a m * n matrix seats  that represent seats distributions in a classroom. If a seat is broken, it is denoted by '#' character otherwise it is den... Topics: Array, Dynamic Programming, Bit Manipulation, Matrix, Bitmask
  • 1485. Minimum Cost to Make at Least One Valid Path in a Grid - Hard - MatrixGiven an m x n grid. Each cell of the grid has a sign pointing to the next cell you should visit if you are currently in this cell. The sign of grid[i... Topics: Array, Breadth-First Search, Graph, Heap (Priority Queue), Matrix, Shortest Path
  • 2588. Maximum Number of Points From Grid Queries - Hard - MatrixYou are given an m x n integer matrix grid and an array queries of size k. Find an array answer of size k such that for each integer queries[i] you st... Topics: Array, Two Pointers, Breadth-First Search, Union Find, Sorting, Heap (Priority Queue), Matrix
  • 1791. Richest Customer Wealth - Easy - MatrixYou are given an m x n integer grid accounts where accounts[i][j] is the amount of money the i​​​​​​​​​​​th​​​​ customer has in the j​​​​​​​​​​​th​​​​... Topics: Array, Matrix
  • 1257. Rank Transform of a Matrix - Hard - MatrixGiven an m x n matrix, return a new matrix answer where answer[row][col] is the rank of matrix[row][col]. The rank is an integer that represents how l... Topics: Array, Union Find, Graph, Topological Sort, Sorting, Matrix
  • 3973. Flip Square Submatrix Vertically - Easy - MatrixYou are given an m x n integer matrix grid, and three integers x, y, and k. The integers x and y represent the row and column indices of the top-left ... Topics: Array, Two Pointers, Matrix
  • 3398. Make a Square with the Same Color - Easy - MatrixYou are given a 2D matrix grid of size 3 x 3 consisting only of characters 'B' and 'W'. Character 'W' represents the white color, and character 'B' re... Topics: Array, Matrix, Enumeration
  • 1145. Number of Submatrices That Sum to Target - Hard - MatrixGiven a matrix and a target, return the number of non-empty submatrices that sum to target. A submatrix x1, y1, x2, y2 is the set of all cells matrix[... Topics: Array, Hash Table, Matrix, Prefix Sum
  • 2108. Minimize the Difference Between Target and Chosen Elements - Medium - MatrixYou are given an m x n integer matrix mat and an integer target. Choose one integer from each row in the matrix such that the absolute difference betw... Topics: Array, Dynamic Programming, Matrix
  • 2146. Check if Word Can Be Placed In Crossword - Medium - MatrixYou are given an m x n matrix board, representing the current state of a crossword puzzle. The crossword contains lowercase English letters (from solv... Topics: Array, Matrix, Enumeration
  • 1311. Largest Magic Square - Medium - MatrixA k x k magic square is a k x k grid filled with integers such that every row sum, every column sum, and both diagonal sums are all equal. The integer... Topics: Array, Matrix, Prefix Sum
  • 2914. Find the Safest Path in a Grid - Medium - MatrixYou are given a 0-indexed 2D matrix grid of size n x n, where (r, c) represents: A cell containing a thief if grid[r][c] = 1 An empty cell if grid[r][... Topics: Array, Binary Search, Breadth-First Search, Union Find, Heap (Priority Queue), Matrix
  • 85. Maximal Rectangle - Hard - MatrixGiven a rows x cols binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.... Topics: Array, Dynamic Programming, Stack, Matrix, Monotonic Stack
  • 1104. Coloring A Border - Medium - MatrixYou are given an m x n integer matrix grid, and three integers row, col, and color. Each value in the grid represents the color of the grid square at ... Topics: Array, Depth-First Search, Breadth-First Search, Matrix
  • 3677. Maximum Amount of Money Robot Can Earn - Medium - MatrixYou are given an m x n grid. A robot starts at the top-left corner of the grid (0, 0) and wants to reach the bottom-right corner (m - 1, n - 1). The r... Topics: Array, Dynamic Programming, Matrix
  • 1990. Get Biggest Three Rhombus Sums in a Grid - Medium - MatrixYou are given an m x n integer matrix grid​​​. A rhombus sum is the sum of the elements that form the border of a regular rhombus shape in grid​​​. Th... Topics: Array, Math, Sorting, Heap (Priority Queue), Matrix, Prefix Sum
  • 3850. Equal Sum Grid Partition II - Hard - MatrixYou are given an m x n matrix grid of positive integers. Your task is to determine if it is possible to make either one horizontal or one vertical cut... Topics: Array, Hash Table, Matrix, Enumeration, Prefix Sum
  • 1727. Cat and Mouse II - Hard - MatrixA game is played by a cat and a mouse named Cat and Mouse. The environment is represented by a grid of size rows x cols, where each element is a wall,... Topics: Array, Math, Dynamic Programming, Graph, Topological Sort, Memoization, Matrix, Game Theory
  • 821. Bricks Falling When Hit - Hard - MatrixYou are given an m x n binary grid, where each 1 represents a brick and 0 represents an empty space. A brick is stable if: It is directly connected to... Topics: Array, Union Find, Matrix
  • 304. Range Sum Query 2D - Immutable - Medium - MatrixGiven a 2D matrix matrix, handle multiple queries of the following type: Calculate the sum of the elements of matrix inside the rectangle defined by i... Topics: Array, Design, Matrix, Prefix Sum
  • 2708. Find the String with LCP - Hard - MatrixWe define the lcp matrix of any 0-indexed string word of n lowercase English letters as an n x n grid such that: lcp[i][j] is equal to the length of t... Topics: Array, String, Dynamic Programming, Greedy, Union Find, Matrix
  • 2737. Row With Maximum Ones - Easy - MatrixGiven a m x n binary matrix mat, find the 0-indexed position of the row that contains the maximum count of ones, and the number of ones in that row. I... Topics: Array, Matrix
  • 1716. Maximum Non Negative Product in a Matrix - Medium - MatrixYou are given a m x n matrix grid. Initially, you are located at the top-left corner (0, 0), and in each step, you can only move right or down in the ... Topics: Array, Dynamic Programming, Matrix
  • 3335. Minimum Operations to Write the Letter Y on a Grid - Medium - MatrixYou are given a 0-indexed n x n grid where n is odd, and grid[r][c] is 0, 1, or 2. We say that a cell belongs to the Letter Y if it belongs to one of ... Topics: Array, Hash Table, Matrix, Counting
  • 3391. Maximum Difference Score in a Grid - Medium - MatrixYou are given an m x n matrix grid consisting of positive integers. You can move from a cell in the matrix to any other cell that is either to the bot... Topics: Array, Dynamic Programming, Matrix
  • 3215. Matrix Similarity After Cyclic Shifts - Easy - MatrixYou are given an m x n integer matrix mat and an integer k. The matrix rows are 0-indexed. The following proccess happens k times: Even-indexed rows (... Topics: Array, Math, Matrix, Simulation
  • 1242. Matrix Block Sum - Medium - MatrixGiven a m x n matrix mat and an integer k, return a matrix answer where each answer[i][j] is the sum of all elements mat[r][c] for: i - k <= r <= i + ... Topics: Array, Matrix, Prefix Sum
  • 919. Projection Area of 3D Shapes - Easy - MatrixYou are given an n x n grid where we place some 1 x 1 x 1 cubes that are axis-aligned with the x, y, and z axes. Each value v = grid[i][j] represents ... Topics: Array, Math, Geometry, Matrix
  • 2625. Increment Submatrices by One - Medium - MatrixYou are given a positive integer n, indicating that we initially have an n x n 0-indexed integer matrix mat filled with zeroes. You are also given a 2... Topics: Array, Matrix, Prefix Sum
  • 3927. Minimum Cost Path with Alternating Directions II - Medium - MatrixYou are given two integers m and n representing the number of rows and columns of a grid, respectively. The cost to enter cell (i, j) is defined as (i... Topics: Array, Dynamic Programming, Matrix
  • 3884. Minimum Absolute Difference in Sliding Submatrix - Medium - MatrixYou are given an m x n integer matrix grid and an integer k. For every contiguous k x k submatrix of grid, compute the minimum absolute difference bet... Topics: Array, Sorting, Matrix
  • 3107. Maximum Spending After Buying Items - Hard - MatrixYou are given a 0-indexed m * n integer matrix values, representing the values of m * n different items in m different shops. Each shop has n items wh... Topics: Array, Greedy, Sorting, Heap (Priority Queue), Matrix
  • 1463. The K Weakest Rows in a Matrix - Easy - MatrixYou are given an m x n binary matrix mat of 1's (representing soldiers) and 0's (representing civilians). The soldiers are positioned in front of the ... Topics: Array, Binary Search, Sorting, Heap (Priority Queue), Matrix
  • 1691. Minimum Number of Days to Disconnect Island - Hard - MatrixYou are given an m x n binary grid grid where 1 represents land and 0 represents water. An island is a maximal 4-directionally (horizontal or vertical... Topics: Array, Depth-First Search, Breadth-First Search, Matrix, Strongly Connected Component
  • 3837. Grid Teleportation Traversal - Medium - MatrixYou are given a 2D character grid matrix of size m x n, represented as an array of strings, where matrix[i][j] represents the cell at the intersection... Topics: Array, Hash Table, Breadth-First Search, Matrix
  • 2132. Convert 1D Array Into 2D Array - Easy - MatrixYou are given a 0-indexed 1-dimensional (1D) integer array original, and two integers, m and n. You are tasked with creating a 2-dimensional (2D) arra... Topics: Array, Matrix, Simulation
  • 3578. Construct 2D Grid Matching Graph Layout - Hard - MatrixYou are given a 2D integer array edges representing an undirected graph having n nodes, where edges[i] = [ui, vi] denotes an edge between nodes ui and... Topics: Array, Hash Table, Graph, Matrix
  • 3870. Minimum Moves to Clean the Classroom - Medium - MatrixYou are given an m x n grid classroom where a student volunteer is tasked with cleaning up litter scattered around the room. Each cell in the grid is ... Topics: Array, Hash Table, Bit Manipulation, Breadth-First Search, Matrix
  • 2801. Difference of Number of Distinct Values on Diagonals - Medium - MatrixGiven a 2D grid of size m x n, you should find the matrix answer of size m x n. The cell answer[r][c] is calculated by looking at the diagonal values ... Topics: Array, Hash Table, Matrix
  • 2585. Delete Greatest Value in Each Row - Easy - MatrixYou are given an m x n matrix grid consisting of positive integers. Perform the following operation until grid becomes empty: Delete the element with ... Topics: Array, Sorting, Heap (Priority Queue), Matrix, Simulation
  • 750. Contain Virus - Hard - MatrixA virus is spreading rapidly, and your task is to quarantine the infected area by installing walls. The world is modeled as an m x n binary grid isInf... Topics: Array, Depth-First Search, Breadth-First Search, Matrix, Simulation
  • 3558. Find a Safe Walk Through a Grid - Medium - MatrixYou are given an m x n binary matrix grid and an integer health. You start on the upper-left corner (0, 0) and would like to get to the lower-right co... Topics: Array, Breadth-First Search, Graph, Heap (Priority Queue), Matrix, Shortest Path
  • 675. Cut Off Trees for Golf Event - Hard - MatrixYou are asked to cut off all the trees in a forest for a golf event. The forest is represented as an m x n matrix. In this matrix: 0 means the cell ca... Topics: Array, Breadth-First Search, Heap (Priority Queue), Matrix
  • 1041. Available Captures for Rook - Easy - MatrixYou are given an 8 x 8 matrix representing a chessboard. There is exactly one white rook represented by 'R', some number of white bishops 'B', and som... Topics: Array, Matrix, Simulation
  • 1386. Shift 2D Grid - Easy - MatrixGiven a 2D grid of size m x n and an integer k. You need to shift the grid k times. In one shift operation: Element at grid[i][j] moves to grid[i][j +... Topics: Array, Matrix, Simulation
  • 2398. Check if Matrix Is X-Matrix - Easy - MatrixA square matrix is said to be an X-Matrix if both of the following conditions hold: All the elements in the diagonals of the matrix are non-zero. All ... Topics: Array, Matrix
  • 1394. Minimum Path Cost in a Grid - Medium - MatrixYou are given a 0-indexed m x n integer matrix grid consisting of distinct integers from 0 to m * n - 1. You can move in this matrix from a cell to an... Topics: Array, Dynamic Programming, Matrix
  • 3648. Find the Maximum Number of Fruits Collected - Hard - MatrixThere is a game dungeon comprised of n x n rooms arranged in a grid. You are given a 2D array fruits of size n x n, where fruits[i][j] represents the ... Topics: Array, Dynamic Programming, Matrix
  • 1704. Special Positions in a Binary Matrix - Easy - MatrixGiven an m x n binary matrix mat, return the number of special positions in mat. A position (i, j) is called special if mat[i][j] == 1 and all other e... Topics: Array, Matrix
  • 2160. Minimum Operations to Make a Uni-Value Grid - Medium - MatrixYou are given a 2D integer grid of size m x n and an integer x. In one operation, you can add x to or subtract x from any element in the grid. A uni-v... Topics: Array, Math, Sorting, Matrix
  • 3092. Minimum Moves to Spread Stones Over Grid - Medium - MatrixYou are given a 0-indexed 2D integer matrix grid of size 3 * 3, representing the number of stones in each cell. The grid contains exactly 9 stones, an... Topics: Array, Dynamic Programming, Breadth-First Search, Matrix
  • 2722. Prime In Diagonal - Easy - MatrixYou are given a 0-indexed two-dimensional integer array nums. Return the largest prime number that lies on at least one of the diagonals of nums. In c... Topics: Array, Math, Matrix, Number Theory
  • 3470. Maximum Score From Grid Operations - Hard - MatrixYou are given a 2D matrix grid of size n x n. Initially, all cells of the grid are colored white. In one operation, you can select any cell of indices... Topics: Array, Dynamic Programming, Matrix, Prefix Sum
  • 2631. Sort the Students by Their Kth Score - Medium - MatrixThere is a class with m students and n exams. You are given a 0-indexed m x n integer matrix score, where each row represents one student and score[i]... Topics: Array, Sorting, Matrix
  • 363. Max Sum of Rectangle No Larger Than K - Hard - MatrixGiven an m x n matrix matrix and an integer k, return the max sum of a rectangle in the matrix such that its sum is no larger than k. It is guaranteed... Topics: Array, Binary Search, Matrix, Prefix Sum, Ordered Set
  • 1073. Number of Enclaves - Medium - MatrixYou are given an m x n binary matrix grid, where 0 represents a sea cell and 1 represents a land cell. A move consists of walking from one land cell t... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
  • 2244. Number of Laser Beams in a Bank - Medium - MatrixAnti-theft security devices are activated inside a bank. You are given a 0-indexed binary string array bank representing the floor plan of the bank, w... Topics: Array, Math, String, Matrix
  • 2508. Maximum Sum of an Hourglass - Medium - MatrixYou are given an m x n integer matrix grid. We define an hourglass as a part of the matrix with the following form: Return the maximum sum of the elem... Topics: Array, Matrix, Prefix Sum
  • 2375. Minimum Obstacle Removal to Reach Corner - Hard - MatrixYou are given a 0-indexed 2D integer array grid of size m x n. Each cell has one of two values: 0 represents an empty cell, 1 represents an obstacle t... Topics: Array, Breadth-First Search, Graph, Heap (Priority Queue), Matrix, Shortest Path
  • 2728. Sum in a Matrix - Medium - MatrixYou are given a 0-indexed 2D integer array nums. Initially, your score is 0. Perform the following operations until the matrix becomes empty: From eac... Topics: Array, Sorting, Heap (Priority Queue), Matrix, Simulation
  • 1389. Minimum Moves to Move a Box to Their Target Location - Hard - MatrixA storekeeper is a game in which the player pushes boxes around in a warehouse trying to get them to target locations. The game is represented by an m... Topics: Array, Breadth-First Search, Heap (Priority Queue), Matrix
  • 1094. Matrix Cells in Distance Order - Easy - MatrixYou are given four integers row, cols, rCenter, and cCenter. There is a rows x cols matrix and you are on the cell with the coordinates (rCenter, cCen... Topics: Array, Math, Geometry, Sorting, Matrix
  • 2089. Maximum Matrix Sum - Medium - MatrixYou are given an n x n integer matrix. You can do the following operation any number of times: Choose any two adjacent elements of matrix and multiply... Topics: Array, Greedy, Matrix
  • 3822. Fill a Special Grid - Medium - MatrixYou are given a non-negative integer n representing a 2n x 2n grid. You must fill the grid with integers from 0 to 22n - 1 to make it special. A grid ... Topics: Array, Divide and Conquer, Matrix
  • 895. Shortest Path to Get All Keys - Hard - MatrixYou are given an m x n grid grid where: '.' is an empty cell. '#' is a wall. '@' is the starting point. Lowercase letters represent keys. Uppercase le... Topics: Array, Bit Manipulation, Breadth-First Search, Matrix
  • 1331. Path with Maximum Gold - Medium - MatrixIn a gold mine grid of size m x n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the ma... Topics: Array, Backtracking, Matrix
  • 3415. Check if Grid Satisfies Conditions - Easy - MatrixYou are given a 2D matrix grid of size m x n. You need to check if each cell grid[i][j] is: Equal to the cell below it, i.e. grid[i][j] == grid[i + 1]... Topics: Array, Matrix
  • 3764. Maximum Sum With at Most K Elements - Medium - MatrixYou are given a 2D integer matrix grid of size n x m, an integer array limits of length n, and an integer k. The task is to find the maximum sum of at... Topics: Array, Greedy, Sorting, Heap (Priority Queue), Matrix
  • 1413. Maximum Side Length of a Square with Sum Less than or Equal to Threshold - Medium - MatrixGiven a m x n matrix mat and an integer threshold, return the maximum side-length of a square with a sum less than or equal to threshold or return 0 i... Topics: Array, Binary Search, Matrix, Prefix Sum
  • 3733. Length of Longest V-Shaped Diagonal Segment - Hard - MatrixYou are given a 2D integer matrix grid of size n x m, where each element is either 0, 1, or 2. A V-shaped diagonal segment is defined as: The segment ... Topics: Array, Dynamic Programming, Memoization, Matrix
  • 1409. Minimum Number of Flips to Convert Binary Matrix to Zero Matrix - Hard - MatrixGiven a m x n binary matrix mat. In one step, you can choose one cell and flip it and all the four neighbors of it if they exist (Flip is changing 1 t... Topics: Array, Hash Table, Bit Manipulation, Breadth-First Search, Matrix
  • 1476. Count Negative Numbers in a Sorted Matrix - Easy - MatrixGiven a m x n matrix grid which is sorted in non-increasing order both row-wise and column-wise, return the number of negative numbers in grid.... Topics: Array, Binary Search, Matrix
  • 825. Max Increase to Keep City Skyline - Medium - MatrixThere is a city composed of n x n blocks, where each block contains a single building shaped like a vertical square prism. You are given a 0-indexed n... Topics: Array, Greedy, Matrix

Related LeetCode Topics

Matrix LeetCode Problems - Interview Coder