[LeetCode] 1267. Count Servers that Communicate (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명You are given a map of a server center, represented as a m * n integer matrix grid, where 1 means that on that cell there is a server and 0 means that it is no server. Two servers are said to communicate if they are on the same row or on the same column.Return the number of servers that communicate with any other server. 문제 예제Example 1:Input: grid = [[1,0],[0,1]] Output: 0 Explan..
[LeetCode] 1765. Map of Highest Peak (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명You are given an integer matrix isWater of size m x n that represents a map of land and water cells.If isWater[i][j] == 0, cell (i, j) is a land cell.If isWater[i][j] == 1, cell (i, j) is a water cell.You must assign each cell a height in a way that follows these rules:The height of each cell must be non-negative.If the cell is a water cell, its height must be 0.Any two adjacent ..
[LeetCode] 2017. Grid Game (Python)
·
알고리즘/LeetCode
난이도: Medium 문제 설명You are given a 0-indexed 2D array grid of size 2 x n, where grid[r][c] represents the number of points at position (r, c) on the matrix. Two robots are playing a game on this matrix. Both robots initially start at (0, 0) and want to reach (1, n-1). Each robot may only move to the right ((r, c) to (r, c + 1)) or down ((r, c) to (r + 1, c)). At the start of the game, the first ro..
[LeetCode] 2661. First Completely Painted Row or Column (Python)
·
알고리즘/LeetCode
난이도: Medium 문제 설명You are given a 0-indexed integer array arr, and an m x n integer matrix mat. arr and mat both contain all the integers in the range [1, m * n]. Go through each index i in arr starting from index 0 and paint the cell in mat containing the integer arr[i]. Return the smallest index i at which either a row or a column will be completely painted in mat. 문제 예제Example 1:Input: arr = [..
[LeetCode] 407. Trapping Rain Water II (Python)
·
알고리즘/LeetCode
문제 설명Given an m x n integer matrix heightMap representing the height of each unit cell in a 2D elevation map, return the volume of water it can trap after raining. 문제 예제Example 1:Input: heightMap = [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]]Output: 4Explanation: After the rain, water is trapped between the blocks.We have two small ponds 1 and 3 units trapped.The total volume of water trapped is ..
[LeetCode] 1368. Minimum Cost to Make at Least One Valid Path in a Grid (Python)
·
알고리즘/LeetCode
난이도: Hard문제 설명Given an m x n grid. Each cell of the grid has a sign pointing to the next cell you should visit if you are currently in this cell. The sign of grid[i][j] can be:1 which means go to the cell to the right. (i.e go from grid[i][j] to grid[i][j + 1])2 which means go to the cell to the left. (i.e go from grid[i][j] to grid[i][j - 1])3 which means go to the lower cell. (i.e go from grid..