Algorithm(92)
-
1791. Find Center of Star Graph
class Solution: def findCenter(self, edges: List[List[int]]) -> int: inbound = collections.defaultdict(int) mx = -1 node = -1 for u, v in edges: inbound[u] += 1 inbound[v] += 1 if inbound[u] > mx: mx = inbound[u] node = u if inbound[v] > mx: mx = inbound[v] node ..
2026.05.10 -
1926. Nearest Exit from Entrance in Maze
class Solution: def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int: sy, sx = entrance q = collections.deque([(sy, sx, 0)]) visited = {(sy, sx)} rows = len(maze) cols = len(maze[0]) while q: y, x, step = q.popleft() if maze[y][x] == '.' and (y == rows - 1 or y == 0 or x == 0 or x == cols - 1) \ ..
2026.05.10 -
1930. Unique Length-3 Palindromic Subsequences
1930. Unique Length-3 Palindromic Subsequences [Unique Length-3 Palindromic Subsequences - LeetCodeCan you solve this real interview question? Unique Length-3 Palindromic Subsequences - Given a string s, return the number of unique palindromes of length three that are a subsequence of s. Note that even if there are multiple ways to obtain the same subseleetcode.com](https://leetcode.com/problems..
2026.05.10 -
3889. Mirror Frequency Distance
class Solution: def mirrorFrequency(self, s: str) -> int: freq = collections.Counter(s) diff = 0 visited = set() for ch in set(s): if ch in visited: continue if ch.isalpha(): letter = chr(ord('z') - (ord(ch) - ord('a'))) else: letter = chr(ord('9') - (ord(ch) - ord('0'))) visit..
2026.04.05 -
3882. Minimum XOR Path in a Grid
def minCost(self, grid: list[list[int]]) -> int: rows = len(grid) cols = len(grid[0]) mem = collections.defaultdict(lambda: set()) def dfs(y, x, inc, mn): if y > rows - 1 or x > cols - 1: return cur = inc ^ grid[y][x] if (y, x) in mem and cur in mem[(y, x)]: return mem[(y, x)].add(cur) ..
2026.04.05 -
3880. Minimum Absolute Difference Between Two Values
class Solution: def minAbsoluteDifference(self, nums: list[int]) -> int: def find_diff(nums, mn): stk = [] for i, num in enumerate(nums): if num == 1: stk += (i, num), continue if num == 0: continue while stk: diff = i - stk[-1][0] ..
2026.04.03