[LeetCode] 1462. Course Schedule IV (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명 There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course ai first if you want to take course bi.For example, the pair [0, 1] indicates that you have to take course 0 before you can take course 1.Prerequisites can also be indirect. If cours..
[LeetCode] 2948. Make Lexicographically Smallest Array by Swapping Elements (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명You are given a 0-indexed array of positive integers nums and a positive integer limit. In one operation, you can choose any two indices i and j and swap nums[i] and nums[j] if |nums[i] - nums[j]| . Return the lexicographically smallest array that can be obtained by performing the operation any number of times. An array a is lexicographically smaller than an array b if in the fir..
[LeetCode] 802. Find Eventual Safe States (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명There is a directed graph of n nodes with each node labeled from 0 to n - 1. The graph is represented by a 0-indexed 2D integer array graph where graph[i] is an integer array of nodes adjacent to node i, meaning there is an edge from node i to each node in graph[i]. A node is a terminal node if there are no outgoing edges. A node is a safe node if every possible path starting fro..
[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..