91-Decode-Ways

Fri 14 November 2025

https://leetcode.com/problems/decode-ways

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numDecodings(self, s: str) -> int:
    n = len(s)
    # dp[i] := # Of ways to decode s[i..n)
    dp = [0] * n + [1]

    def isValid(a: chr, b=None) -> bool …

Category: leetcode

Read More

910-Smallest-Range-Ii

Fri 14 November 2025

https://leetcode.com/problems/smallest-range-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def smallestRangeII(self, A: List[int], K: int) -> int:
    A.sort()

    ans = A[-1] - A[0]
    left = A[0] + K
    right = A[-1] - K

    for a, b in zip …

Category: leetcode

Read More

912-Sort-An-Array

Fri 14 November 2025

https://leetcode.com/problems/sort-an-array

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def sortArray(self, nums: List[int]) -> List[int]:
    def mergeSort(A: List[int], l: int, r: int) -> None:
      if l >= r:
        return

      def merge(A: List[int], l: int …

Category: leetcode

Read More

913-Cat-And-Mouse

Fri 14 November 2025

https://leetcode.com/problems/cat-and-mouse

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
from enum import IntEnum


class State(IntEnum):
  kDraw = 0
  kMouseWin = 1
  kCatWin = 2


class Solution:
  def catMouseGame(self, graph: List[List[int]]) -> int:
    n = len(graph)
    # Result of (cat, mouse, move …

Category: leetcode

Read More

914-X-Of-A-Kind-In-A-Deck-Of-Cards

Fri 14 November 2025

https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def hasGroupsSizeX(self, deck: List[int]) -> bool:
    count = Counter(deck)
    return functools.reduce(math.gcd, count.values()) >= 2
new Solution().hasGroupsSizeX()

Score: 5

Category: leetcode

Read More

915-Partition-Array-Into-Disjoint-Intervals

Fri 14 November 2025

https://leetcode.com/problems/partition-array-into-disjoint-intervals

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def partitionDisjoint(self, A: List[int]) -> int:
    n = len(A)
    mini = [0] * (n - 1) + [A[-1]]
    maxi = -math.inf

    for i in range(n - 2, - 1, -1):
      mini[i …

Category: leetcode

Read More

916-Word-Subsets

Fri 14 November 2025

https://leetcode.com/problems/word-subsets

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def wordSubsets(self, A: List[str], B: List[str]) -> List[str]:
    count = Counter()

    for b in B:
      count = count | Counter(b)

    return [a for a in A if Counter …

Category: leetcode

Read More

917-Reverse-Only-Letters

Fri 14 November 2025

https://leetcode.com/problems/reverse-only-letters

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def reverseOnlyLetters(self, S: str) -> str:
    S = list(S)
    i = 0
    j = len(S) - 1

    while i < j:
      while i < j and not S[i].isalpha():
        i += 1
      while …

Category: leetcode

Read More

918-Maximum-Sum-Circular-Subarray

Fri 14 November 2025

https://leetcode.com/problems/maximum-sum-circular-subarray

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def maxSubarraySumCircular(self, A: List[int]) -> int:
    totalSum = 0
    currMaxSum = 0
    currMinSum = 0
    maxSum = -math.inf
    minSum = math.inf

    for a in A:
      totalSum += a
      currMaxSum = max(currMaxSum + a …

Category: leetcode

Read More

92-Reverse-Linked-List-Ii

Fri 14 November 2025

https://leetcode.com/problems/reverse-linked-list-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def reverseBetween(self, head: Optional[ListNode], left: int, right: int) -> Optional[ListNode]:
    if left == 1:
      return self.reverseN(head, right)

    head.next = self.reverseBetween(head.next, left - 1, right …

Category: leetcode

Read More
Page 77 of 146

« Prev Next »