All Posts

Leetcode 1559: Detect Cycles in 2D Grid

Given a 2D grid of characters, find if there exists a cycle where the same character repeats in the grid. A cycle is defined as a path where a character appears 4 or more times, forming a loop that starts and ends at the same cell. The cycle must consist of adjacent cells, and you are not allowed to revisit the previous cell.

Leetcode 1572: Matrix Diagonal Sum

You are given a square matrix of integers. Your task is to calculate the sum of all the elements located on the primary diagonal and the secondary diagonal, excluding the element that appears on both diagonals (i.e., the center element in an odd-sized matrix).

Leetcode 1582: Special Positions in a Binary Matrix

You are given a binary matrix of size m x n, where each element is either 0 or 1. A position (i, j) in the matrix is considered special if mat[i][j] = 1 and all other elements in the same row i and column j are 0. Your task is to find how many such special positions exist in the matrix.

Leetcode 1594: Maximum Non Negative Product in a Matrix

You are given a m x n matrix grid. Starting at the top-left corner (0, 0), you can only move right or down. Your task is to find the path from the top-left to the bottom-right corner that results in the maximum non-negative product of the grid values along the path. If such a path results in a negative product, return -1. The product is calculated by multiplying all grid values visited along the path. You should return the maximum non-negative product modulo 10^9 + 7.

Leetcode 1605: Find Valid Matrix Given Row and Column Sums

You are given two arrays representing the sum of elements in each row and each column of a 2D matrix. The rowSum[i] represents the sum of the elements in the i-th row, and colSum[j] represents the sum of the elements in the j-th column. Your task is to find a matrix of non-negative integers that satisfies these row and column sum requirements.

Leetcode 1631: Path With Minimum Effort

You are a hiker navigating a terrain represented by a 2D grid of heights. Your goal is to find the path from the top-left corner to the bottom-right corner that minimizes the maximum height difference between any two consecutive cells.