1029-Two-City-Scheduling

Sat 17 May 2025

https://leetcode.com/problems/two-city-scheduling

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def twoCitySchedCost(self, costs: List[List[int]]) -> int:
    n = len(costs) // 2

    # How much money can we save if we fly a person to A instead of B?
    # To …

Category: leetcode

Read More

103-Binary-Tree-Zigzag-Level-Order-Traversal

Sat 17 May 2025

https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def zigzagLevelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:
    if not root:
      return []

    ans = []
    q = deque([root])
    isLeftToRight = True

    while q:
      currLevel = []
      for _ in range(len(q)):
        if …

Category: leetcode

Read More

1031-Maximum-Sum-Of-Two-Non-Overlapping-Subarrays

Sat 17 May 2025

https://leetcode.com/problems/maximum-sum-of-two-non-overlapping-subarrays

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def maxSumTwoNoOverlap(self, nums: List[int], firstLen: int, secondLen: int) -> int:
    def helper(l: int, r: int) -> int:
      n = len(nums)
      left = [0] * n
      summ = 0

      for i in …

Category: leetcode

Read More

1033-Moving-Stones-Until-Consecutive

Sat 17 May 2025

https://leetcode.com/problems/moving-stones-until-consecutive

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numMovesStones(self, a: int, b: int, c: int) -> List[int]:
    nums = sorted([a, b, c])

    if nums[2] - nums[0] == 2:
      return [0, 0]
    return [1 if min …

Category: leetcode

Read More

1034-Coloring-A-Border

Sat 17 May 2025

https://leetcode.com/problems/coloring-a-border

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def colorBorder(self, grid: List[List[int]], r0: int, c0: int, color: int) -> List[List[int]]:
    def dfs(i: int, j: int, originalColor: int) -> None:
      if not 0 <= i …

Category: leetcode

Read More

1035-Uncrossed-Lines

Sat 17 May 2025

https://leetcode.com/problems/uncrossed-lines

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def maxUncrossedLines(self, A: List[int], B: List[int]) -> int:
    m = len(A)
    n = len(B)
    dp = [[0] * (n + 1) for _ in range(m + 1)]

    for i in …

Category: leetcode

Read More

1036-Escape-A-Large-Maze

Sat 17 May 2025

https://leetcode.com/problems/escape-a-large-maze

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isEscapePossible(self, blocked: List[List[int]], source: List[int], target: List[int]) -> bool:
    def dfs(i: int, j: int, target: List[int], visited: set) -> bool:
      if not 0 …

Category: leetcode

Read More

1037-Valid-Boomerang

Sat 17 May 2025

https://leetcode.com/problems/valid-boomerang

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isBoomerang(self, points: List[List[int]]) -> bool:
    return (points[1][0] - points[0][0]) * (points[2][1] - points[1][1]) != \
        (points[1][1] - points[0][1]) * (points[2 …

Category: leetcode

Read More

104-Maximum-Depth-Of-Binary-Tree

Sat 17 May 2025

https://leetcode.com/problems/maximum-depth-of-binary-tree

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def maxDepth(self, root: Optional[TreeNode]) -> int:
    if not root:
      return 0
    return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right))
new Solution().maxDepth()

Score: 5

Category: leetcode

Read More

1040-Moving-Stones-Until-Consecutive-Ii

Sat 17 May 2025

https://leetcode.com/problems/moving-stones-until-consecutive-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numMovesStonesII(self, stones: List[int]) -> List[int]:
    n = len(stones)
    minMoves = n

    stones.sort()

    l = 0
    for r, stone in enumerate(stones):
      while stone - stones[l] + 1 > n …

Category: leetcode

Read More
Page 5 of 146

« Prev Next »