48. Rotate Image

You are given an n x n 2D matrix representing an image, rotate the image 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. 1 2 3 4 Example 1: Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] Output: [[7,4,1],[8,5,2],[9,6,3]] 1 2 3 4 Example 2: Input: matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]] Output: [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]] 1 2 3 4 Example 3: Input: matrix = [[1]] Output: [[1]] 1 2 3 4 Example 4: Input: matrix = [[1,2],[3,4]] Output: [[3,1],[4,2]] Constraints:...

<span title='2021-11-30 00:00:00 +0000 UTC'>November 30, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

304. Range Sum Query 2D - Immutable

304. Range Sum Query 2D - Immutable Given a 2D matrix matrix, handle multiple queries of the following type: Calculate the sum of the elements of matrix inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2). Implement the NumMatrix class: NumMatrix(int[][] matrix) Initializes the object with the integer matrix matrix. int sumRegion(int row1, int col1, int row2, int col2) Returns the sum of the elements of matrix inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2)....

<span title='2021-09-02 00:00:00 +0000 UTC'>September 2, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

827. Making A Large Island

827. Making A Large Island You are given an n x n binary matrix grid. You are allowed to change at most one 0 to be 1. Return the size of the largest island in grid after applying this operation. An island is a 4-directionally connected group of 1s. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Example 1: Input: grid = [[1,0],[0,1]] Output: 3 Explanation: Change one 0 to 1 and connect two 1s, then we get an island with area = 3....

<span title='2021-08-06 00:00:00 +0000 UTC'>August 6, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

1329. Sort the Matrix Diagonally

1329. Sort the Matrix Diagonally 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 6 x 3 matrix, includes cells mat[2][0], mat[3][1], and mat[4][2]. Given an m x n matrix mat of integers, sort each matrix diagonal in ascending order and return the resulting matrix....

<span title='2021-07-11 00:00:00 +0000 UTC'>July 11, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

835. Image Overlap

835. Image Overlap You are given two images img1 and img2 both of size n x n, represented as binary, square matrices of the same size. (A binary matrix has only 0s and 1s as values.) We translate one image however we choose (sliding it left, right, up, or down any number of units), and place it on top of the other image. After, the overlap of this translation is the number of positions that have a 1 in both images....

<span title='2021-06-07 00:00:00 +0000 UTC'>June 7, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx