Subrectangle Queries Solution In C++/Python/java/JS Subrectangle Queries Problem Implement the class SubrectangleQueries which receives a rows x cols rectangle as a matrix of integers in the constructor and supports two methods: 1. updateSubrectangle(int row1, int col1, int row2, int col2, int newValue) Updates all values with newValue in the subrectangle whose upper left coordinate
Make a Square with the Same Color Solution In C++/Python/java/JS Problem Description You 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' represents the black color. Your task is to change the color of
Matrix Max Increase to Keep City Skyline Solution In C++/Python/java/JS Problem Description There 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 x n integer matrix grid where grid[r][c] represents the height of the building located in the block
Queens That Can Attack The King Problem Description On 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] = [x_Queeni, y_Queeni] represents the position of the ith black queen on the chessboard. You are also given an
Check if Matrix is X-Matrix Problem Description A square matrix is said to be an X-Matrix if both of the following conditions hold: 1. All the elements in the diagonals of the matrix are non-zero. 2. All other elements are 0. Given a 2D integer array grid of size n x n representing a square
Matrix Find Valid Matrix Given Row and Column Sums Solution In C++/Python/java/JS Problem Description You 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 of the elements of the jth column of a 2D matrix. In other words, you do not know
Matrix Matrix Cells in Distance Order Solution In C++/Python/java/JS Problem Description Given a rows x cols matrix, we are provided with a starting position (rCenter, cCenter). The task is to return the coordinates of all cells in the matrix, sorted by their Manhattan distance from the center. The Manhattan distance between two points (r1, c1) and (r2, c2) is
Game of Life Solution In C++/Python/java/JS Problem Description: According to Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970." The board is made up of an m x n grid of cells, where each cell has
Cyclically Rotating a Grid Solution In C++/Python/java/JS Problem Description You are given an m x n integer matrix grid , where m and n are both even integers, and an integer k. The matrix is composed of several layers, which is shown in the below image, where each color is its own layer: A cyclic rotation of the
Rotating the Box Solution In C++/Python/java/JS Rotating the Box Problem You 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 stationary obstacle '*' Empty '.' The box is rotated 90 degrees clockwise,
Rotate Image Problem Description If you are given an n x n 2D matrix representing an image, rotate it by 90 degrees (clockwise). You have to rotate the image in place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.
Transpose Matrix Solution In C++/Python/java/JS Given 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 matrix's row and column indices. Examples : Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] Output: [[1,4,7],[2,
Matrix Matrix Similarity After Cyclic Shifts Solution In C++/Python/java/JS Matrix Similarity After Cyclic Shifts Problem Description: You are given an m x n integer matrix mat and an integer k. The matrix rows are 0-indexed. The following process happens k times: Even-indexed rows (0, 2, 4, ...) are cyclically shifted to the left. Odd-indexed rows (1, 3, 5, ...) are cyclically
Shift 2D Grid Solution in C++/Java/Python/JS Shift 2D Grid Problem Description: Given 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 + 1] Element at grid[i][n - 1] moves to
Minimum Operations to Write the Letter Y on a Grid Solution In C++/Python/java/JS Minimum Operations to Write the Letter Y on a Grid Problem Description: You 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
Sort the Matrix Diagonally Solution In C++/Python/java/JS Problem Description A 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 direction until reaching the matrix's end. For example, the matrix diagonal starting from mat[2][0], where mat is a
Set Matrix Zeroes Problem Statement Given an m x n integer matrix mat, if an element is 0, set its entire row and column to 0's. You must do it in place. Examples Input: matrix = [[1,1,1],[1,0,1],[1,1,1]] Output: [[1,0,1],[0,0,0]
Modify the Matrix Problem Statement Given a 0-indexed m x n integer matrix matrix, create a new 0-indexed matrix called answer. Make answer equal to matrix, then replace each element with the value -1 with the maximum element in its respective column. Return the matrix answer. Examples: Input: matrix = [[1,2,-1],[4,
Convert 1D Array Into 2D Array Problem Description You 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) array with m rows and n columns using all the elements from the original. The elements from indices 0 to n - 1 (inclusive)