↓Skip to main content

Matrix

LeetCode 2392: Build a Matrix With Conditions
·2 mins
LeetCode Hard Graph Topological-Sort Matrix
LeetCode 2392 note: row and column conditions are independent, so run one topological sort for each; put x at its row and column positions, and return an empty matrix if either has a cycle
LeetCode 3548: Equal Sum Grid Partition II
·3 mins
LeetCode Hard Prefix-Sum Hash-Table Matrix Enumeration
LeetCode 3548 note: try each horizontal cut (transpose for vertical); the difference must equal a cell on the larger side, and a one-row or one-column side can only drop an end cell, while any cell works otherwise
LeetCode 980: Unique Paths III
·2 mins
LeetCode Hard Backtracking Matrix Dfs
LeetCode 980 note: grid backtracking that marks visited cells in place and checks at the end that every empty cell was covered
LeetCode 3989: Maximum Consistent Columns in a Grid
·2 mins
LeetCode Hard Dynamic-Programming Matrix Array
LeetCode 3989 note: the kept columns form a subsequence constrained only between neighbors; an LIS-style DP with dp[j] = the longest valid sequence ending at column j
LeetCode 3651: Minimum Cost Path with Teleportations
·2 mins
LeetCode Hard Dynamic-Programming Grid-Dp Matrix Array
LeetCode 3651 note: compute layer by layer over teleports; arriving at a cell by teleport costs the previous layer’s minimum over cells with value >= it, found with a running minimum after sorting, followed by the usual right / down grid DP
LeetCode 1878: Get Biggest Three Rhombus Sums in a Grid
·3 mins
LeetCode Medium Matrix Enumeration Heap
LeetCode 1878 note: enumerate every top vertex and size, walk the four edges, and keep the three largest distinct sums
LeetCode 1727: Largest Submatrix With Rearrangements
·2 mins
LeetCode Medium Greedy Sorting Matrix
LeetCode 1727 note: compute each row’s heights of consecutive ones above; columns can be reordered, so sort heights descending and the j-th tallest times j + 1 is a candidate
LeetCode 3961: Maximize Sum of Device Ratings
·2 mins
LeetCode Medium Greedy Sorting Matrix
LeetCode 3961 note: every device but one donates its smallest unit to the same device; that device’s rating becomes the global minimum, so pick the one with the smallest second-smallest value
LeetCode 3905: Multi Source Flood Fill
·2 mins
LeetCode Medium Bfs Matrix
LeetCode 3905 note: multi-source BFS one layer at a time, collecting the maximum color per cell before writing the layer back
LeetCode 3898: Find the Degree of Each Vertex
·1 min
LeetCode Easy Graph Matrix Array
LeetCode 3898 note: the number of ones in row i of the adjacency matrix is vertex i’s degree
LeetCode 1975: Maximum Matrix Sum
·2 mins
LeetCode Medium Greedy Matrix Array
LeetCode 1975 note: minus signs can travel anywhere in pairs but the parity of the negative count never changes; with an odd count, leave one on the smallest absolute value
LeetCode 3195: Find the Minimum Area to Cover All Ones I
·1 min
LeetCode Medium Array Matrix
LeetCode 3195 note: track the topmost, bottommost, leftmost and rightmost 1; the area is height times width