All Posts

Leetcode 1139: Largest 1-Bordered Square

Given a 2D grid of 0s and 1s, return the number of elements in the largest square subgrid that has 1s on its border and 0s inside. If no such subgrid exists, return 0.

Leetcode 1162: As Far from Land as Possible

Given a square grid of size n x n containing only 0s (water) and 1s (land), find the water cell that is farthest from any land cell based on Manhattan distance, and return that distance. If the grid has no water or no land, return -1.

Leetcode 1219: Path with Maximum Gold

In a gold mine grid of size m x n, each cell contains an integer representing the amount of gold in that cell. A cell with 0 means no gold is present. The task is to find the maximum amount of gold that can be collected by following certain movement rules: You can move one step in any of the four directions (left, right, up, down), but you cannot visit the same cell twice, and you cannot move to a cell that contains 0 gold.

Leetcode 1222: Queens That Can Attack the King

On an 8x8 chessboard, there are multiple black queens and one white king. You are given the positions of the black queens and the white king. Your task is to find all the black queens that can directly attack the white king. A queen can attack the king if they share the same row, column, or diagonal.

Leetcode 1253: Reconstruct a 2-Row Binary Matrix

You are given a binary matrix with 2 rows and n columns, where each element is either 0 or 1. The sum of elements in the 0-th (upper) row is given by upper, the sum of elements in the 1-st (lower) row is given by lower, and the column-wise sum is given by colsum. Your task is to reconstruct the matrix based on these sums. If reconstruction is not possible, return an empty matrix.

Leetcode 1254: Number of Closed Islands

You are given a 2D grid with 0s (land) and 1s (water). An island is a group of 0s connected 4-directionally, and a closed island is a group of 0s completely surrounded by 1s. Your task is to count how many closed islands are present in the grid.