Count Submatrices with Top-Left Element and Sum Less Than k Solution In C++/Python/java/JS Problem Description: You are given a 0-indexed integer matrix grid and an integer k. Return the number of submatrices that contain the top-left element of the grid, and have a sum less than or equal to k. Examples: Input: grid = [[7,6,3],[6,6,1]], k = 18 Output: 4
Spiral Matrix II Problem Statement Given a positive integer n, generate an n x n matrix filled with elements from 1 to n² in spiral order. Problem Explanation What is Spiral Order? Spiral order means filling the matrix in a clockwise direction, starting from the top-left corner. The numbers should fill the outer
Spiral Matrix Problem Description Given an m x n matrix, return all elements of the matrix in spiral order. Problem Explanation Given an m x n matrix, our task is to traverse and return all elements in a spiral order using a specific pattern of movements. The journey begins at the top-left
Find the Grid of Region Average Solution In C++/Python/java/JS Problem Description: You are given m x n grid image which represents a grayscale image, where image[i][j] represents a pixel with intensity in the range [0..255]. You are also given a non-negative integer threshold. Two pixels are adjacent if they share an edge. A region is a
Maximum Matrix Sum Problem Description You 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 each of them by -1. Two elements are considered adjacent if and only if they share a border. Your
Matrix Maximum Sum of an Hourglass Solution In C++/Python/java/JS Problem Description You are given an m x n integer matrix grid. Return the maximum sum of the elements of an hourglass. Note that an hourglass cannot be rotated and must be entirely contained within the matrix. Example Input: grid = [[6,2,1,3],[4,2,1,5],[9,2,
Largest Local Values in a Matrix Problem Statement You 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 largest value of the 3 x 3 matrix in grid centered around row i + 1
Matrix Matrix Block Sum Solution In C++/Python/java/JS Matrix Block Sum Problem Given 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 + k, j - k <= c <= j + k,
Matrix Diagonal Traverse Solution In C++/Python/java/JS Problem Description Given an m x n matrix mat, return an array of all the elements of the array in a diagonal order. Example Input: mat = [[1,2,3],[4,5,6],[7,8,9]] Output: [1,2,4,7,5,3,6,8,9] Explanation: We pick elements diagonally.
Prime In Diagonal Problem Description You 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 case, no prime is present on any of the diagonals, return 0. Note that: 1) An integer is prime if it is
Matrix Diagonal Sum Problem Description Given 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 elements on the secondary diagonal that are not part of the primary diagonal. What is a Square Matrix? A square matrix
Difference Between Ones and Zeros in Row and Column Solution In C++/Python/java/JS Problem Description You 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 of ones in the ith row be onesRow_i. Let the number of ones in the jth column be onesCol_
Equal Row and Column Pairs Solution In C++/Python/java/JS Equal Row and Column Pairs Problem Description: Given 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 considered equal if they contain the same elements in the same order
Lucky Numbers in a Matrix Problem Statement Given 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 it is the minimum element in its row and maximum in its column. Examples: Input: matrix = [[3,7,
Richest Customer Wealth Problem Statement You 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 bank. Return the wealth that the richest customer has. A customer's wealth is the amount of money they
Row with Maximum ones Problem Statement Given 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. In case there are multiple rows that have the maximum count of ones, the row with the smallest
Minimum Operations to Make a Uni-Value Grid Solution In C++/Python/java/JS Problem Description You 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-value grid is a grid where all the elements of it are equal. Return
Image Overlap Solution In C++/Python/java/JS Problem Description You 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 translate one image however we choose by sliding all the 1 bits left, right, up, and/or down any
Where Will the Ball Fall Solution In C++/Python/java/JS Problem Description You 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 diagonal board spanning two corners of the cell that can redirect a ball
Number of Laser Beams in a Bank Solution In C++/Python/java/JS Problem Description A bank's security system is represented as an m x n binary string array bank, where '1' denotes a security device and '0' represents an empty cell. A laser beam is formed between two devices if they are in different rows (r1
Valid Tic-Tac-Toe State Solution In C++/Python/java/JS Problem Description In this problem, you are given a 3x3 Tic-Tac-Toe board represented as a string array. The goal is to determine if the given board configuration could have been reached through a sequence of valid moves according to the rules of Tic-Tac-Toe. The game follows a turn-based approach where
Check if Move is Legal Solution In C++/Python/java/JS Problem Description: You are given a 0-indexed 8 x 8 grid board, where board[r][c] represents the cell (r, c) on a game board. On the board, free cells are represented by '.', white cells are represented by 'W', and black cells are represented by '
Valid Sudoku Solution In C++/Python/java/JS Problem Description: Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: 1. Each row must contain the digits 1-9 without repetition. 2. Each column must contain the digits 1-9 without repetition. 3. Each of the nine
Find the Minimum Area to Cover All Ones II Solution In C++/Python/java/JS Find the Minimum Area to Cover All Ones II Problem You are given a 2D binary array grid. You need to find 3 non-overlapping rectangles having non-zero areas with horizontal and vertical sides such that all the 1's in grid lie inside these rectangles. Return the minimum possible
Find the Minimum Area to Cover All Ones I Solution In C++/Python/java/JS Find the Minimum Area to Cover All Ones I Problem You are given a 2D binary array grid. Find a rectangle with horizontal and vertical sides with the smallest area, such that all the 1's in grid lie inside this rectangle. Return the minimum possible area of the