954-Array-Of-Doubled-Pairs

Sat 17 May 2025

https://leetcode.com/problems/array-of-doubled-pairs

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

    for key in sorted(count, key=abs):
      if count[key] > count[2 * key]:
        return False
      count[2 * key] -= count …

Category: leetcode

Read More

957-Prison-Cells-After-N-Days

Sat 17 May 2025

https://leetcode.com/problems/prison-cells-after-n-days

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def prisonAfterNDays(self, cells: List[int], N: int) -> List[int]:
    nextDayCells = [0] * len(cells)
    day = 0

    while N > 0:
      N -= 1
      for i in range(1, len(cells) - 1 …

Category: leetcode

Read More

96-Unique-Binary-Search-Trees

Sat 17 May 2025

https://leetcode.com/problems/unique-binary-search-trees

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numTrees(self, n: int) -> int:
    # G[i] := # Of unique BST's that store values 1..i
    G = [1, 1] + [0] * (n - 1)

    for i in range(2, n …

Category: leetcode

Read More

961-N-Repeated-Element-In-Size-2N-Array

Sat 17 May 2025

https://leetcode.com/problems/n-repeated-element-in-size-2n-array

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def repeatedNTimes(self, A: List[int]) -> int:
    for i in range(len(A) - 2):
      if A[i] == A[i + 1] or A[i] == A[i + 2]:
        return A[i …

Category: leetcode

Read More

962-Maximum-Width-Ramp

Sat 17 May 2025

https://leetcode.com/problems/maximum-width-ramp

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

    for i, num in enumerate(nums):
      if stack == [] or num <= nums[stack[-1]]:
        stack.append(i)

    for i, num …

Category: leetcode

Read More

963-Minimum-Area-Rectangle-Ii

Sat 17 May 2025

https://leetcode.com/problems/minimum-area-rectangle-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def minAreaFreeRect(self, points: List[List[int]]) -> float:
    ans = math.inf
    # For each A, B pair points, {hash(A, B): (ax, ay, bx, by)}
    centerToPoints = defaultdict(list)

    for ax …

Category: leetcode

Read More

964-Least-Operators-To-Express-Number

Sat 17 May 2025

https://leetcode.com/problems/least-operators-to-express-number

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def leastOpsExpressTarget(self, x: int, target: int) -> int:
    @functools.lru_cache(None)
    def dfs(target):
      if x > target:
        return min(2 * target - 1, 2 * (x - target))
      if x == target:
        return …

Category: leetcode

Read More

966-Vowel-Spellchecker

Sat 17 May 2025

https://leetcode.com/problems/vowel-spellchecker

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def spellchecker(self, wordlist: List[str], queries: List[str]) -> List[str]:
    def lowerKey(word: str) -> str:
      return '$' + ''.join([c.lower() for c in word])

    def vowelKey(word: str) -> str …

Category: leetcode

Read More

969-Pancake-Sorting

Sat 17 May 2025

https://leetcode.com/problems/pancake-sorting

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

    for target in range(len(A), 0, -1):
      index = A.index(target)
      A[:index + 1] = A[:index + 1][::-1]
      A …

Category: leetcode

Read More

97-Interleaving-String

Sat 17 May 2025

https://leetcode.com/problems/interleaving-string

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isInterleave(self, s1: str, s2: str, s3: str) -> bool:
    m = len(s1)
    n = len(s2)
    if m + n != len(s3):
      return False

    # dp[i][j] := true if s3 …

Category: leetcode

Read More
Page 74 of 77

« Prev Next »