1019-Next-Greater-Node-In-Linked-List

Sat 17 May 2025

https://leetcode.com/problems/next-greater-node-in-linked-list

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def nextLargerNodes(self, head: ListNode) -> List[int]:
    ans = []
    stack = []

    while head:
      while stack and head.val > ans[stack[-1]]:
        index = stack.pop()
        ans[index] = head.val
      stack.append(len …

Category: leetcode

Read More

102-Binary-Tree-Level-Order-Traversal

Sat 17 May 2025

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

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

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

    while q:
      currLevel = []
      for _ in range(len(q)):
        node = q.popleft …

Category: leetcode

Read More

1023-Camelcase-Matching

Sat 17 May 2025

https://leetcode.com/problems/camelcase-matching

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def camelMatch(self, queries: List[str], pattern: str) -> List[bool]:
    def isMatch(q: str) -> bool:
      j = 0

      for i, c in enumerate(q):
        if j < len(pattern) and c …

Category: leetcode

Read More

1024-Video-Stitching

Sat 17 May 2025

https://leetcode.com/problems/video-stitching

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def videoStitching(self, clips: List[List[int]], time: int) -> int:
    ans = 0
    end = 0
    farthest = 0

    clips.sort()

    i = 0
    while farthest < time:
      while i < len(clips) and clips …

Category: leetcode

Read More

1025-Divisor-Game

Sat 17 May 2025

https://leetcode.com/problems/divisor-game

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def divisorGame(self, N: int) -> bool:
    return N % 2 == 0
new Solution().divisorGame()

Score: 5

Category: leetcode

Read More

1027-Longest-Arithmetic-Subsequence

Sat 17 May 2025

https://leetcode.com/problems/longest-arithmetic-subsequence

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def longestArithSeqLength(self, nums: List[int]) -> int:
    n = len(nums)
    ans = 0
    # dp[i][k] := length of the longest arithmetic subseq ofnums
    # nums[0..i] with k = diff + 500 …

Category: leetcode

Read More

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
Page 3 of 77

« Prev Next »