[LeetCode] 3243. Shortest Distance After Road Addition Queries I - Python
·
알고리즘/LeetCode
난이도: medium 문제 설명You are given an integer n and a 2D integer array queries. There are n cities numbered from 0 to n - 1. Initially, there is a unidirectional road from city i to city i + 1 for all 0  queries[i] = [ui, vi] represents the addition of a new unidirectional road from city ui to city vi. After each query, you need to find the length of the shortest path from city 0 to city n - 1. Retu..
[LeetCode] 2924. Find Champion II - Python
·
알고리즘/LeetCode
난이도: Medium 문제 설명There are n teams numbered from 0 to n - 1 in a tournament; each team is also a node in a DAG. You are given the integer n and a 0-indexed 2D integer array edges of length m representing the DAG, where edges[i] = [ui, vi] indicates that there is a directed edge from team ui to team vi in the graph. A directed edge from a to b in the graph means that team a is stronger than team ..
[LeetCode] 773. Sliding Puzzle - Python
·
알고리즘/LeetCode
난이도: Hard문제 설명On an 2 x 3 board, there are five tiles labeled from 1 to 5, and an empty square represented by 0. A move consists of choosing 0 and a 4-directionally adjacent number and swapping it.The state of the board is solved if and only if the board is [[1,2,3],[4,5,0]].Given the puzzle board board, return the least number of moves required so that the state of the board is solved. If it is..
[LeetCode] 1861. Rotating the Box - Python
·
알고리즘/LeetCode
문제 설명You are given an m x n matrix of characters box 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, causing some of the stones to fall due to gravity. Each stone falls down until it lands on an obstacle, another stone, or the bottom of the box. Gravity does not affect the obstac..
[LeetCode] 2257. Count Unguarded Cells in the Grid - Python
·
알고리즘/LeetCode
난이도: Medium 문제 설명You are given two integers m and n representing a 0-indexed m x n grid. You are also given two 2D integer arrays guards and walls where guards[i] = [rowi, coli] and walls[j] = [rowj, colj] represent the positions of the ith guard and jth wall respectively.A guard can see every cell in the four cardinal directions (north, east, south, or west) starting from their position unless ..
[LeetCode] 2461. Maximum Sum of Distinct Subarrays With Length K - Python
·
알고리즘/LeetCode
난이도: Medium문제 설명You are given an integer array nums and an integer k. Find the maximum subarray sum of all the subarrays of nums that meet the following conditions:The length of the subarray is k, andAll the elements of the subarray are distinct.Return the maximum subarray sum of all the subarrays that meet the conditions. If no subarray meets the conditions, return 0.A subarray is a contiguous ..