878-Nth-Magical-Number

Fri 14 November 2025

https://leetcode.com/problems/nth-magical-number

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def nthMagicalNumber(self, n: int, a: int, b: int) -> int:
    lcm = a * b // math.gcd(a, b)
    l = min(a, b)
    r = min(a, b) * n

    while l < r …

Category: leetcode

Read More

88-Merge-Sorted-Array

Fri 14 November 2025

https://leetcode.com/problems/merge-sorted-array

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:
    i = m - 1      # nums1's index (actual nums)
    j = n - 1      # nums2's index
    k …

Category: leetcode

Read More

880-Decoded-String-At-Index

Fri 14 November 2025

https://leetcode.com/problems/decoded-string-at-index

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def decodeAtIndex(self, s: str, k: int) -> str:
    size = 0

    for c in s:
      if c.isdigit():
        size *= int(c)
      else:
        size += 1

    for c in reversed(s):
      k …

Category: leetcode

Read More

881-Boats-To-Save-People

Fri 14 November 2025

https://leetcode.com/problems/boats-to-save-people

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numRescueBoats(self, people: List[int], limit: int) -> int:
    ans = 0
    i = 0
    j = len(people) - 1

    people.sort()

    while i <= j:
      remain = limit - people[j]
      j -= 1
      if …

Category: leetcode

Read More

882-Reachable-Nodes-In-Subdivided-Graph

Fri 14 November 2025

https://leetcode.com/problems/reachable-nodes-in-subdivided-graph

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def reachableNodes(self, edges: List[List[int]], maxMoves: int, n: int) -> int:
    graph = [[] for _ in range(n)]
    minHeap = [(0, 0)]  # (d, u)
    dist = [maxMoves + 1] * n
    dist[0 …

Category: leetcode

Read More

883-Projection-Area-Of-3D-Shapes

Fri 14 November 2025

https://leetcode.com/problems/projection-area-of-3d-shapes

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def projectionArea(self, grid: List[List[int]]) -> int:
    return sum(a > 0 for row in grid for a in row) + sum(max(row) for row in grid) + sum(max …

Category: leetcode

Read More

884-Uncommon-Words-From-Two-Sentences

Fri 14 November 2025

https://leetcode.com/problems/uncommon-words-from-two-sentences

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def uncommonFromSentences(self, A: str, B: str) -> List[str]:
    count = Counter((A + ' ' + B).split())
    return [word for word, freq in count.items() if freq == 1]
new Solution().uncommonFromSentences()

Score …

Category: leetcode

Read More

885-Spiral-Matrix-Iii

Fri 14 November 2025

https://leetcode.com/problems/spiral-matrix-iii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def spiralMatrixIII(self, R: int, C: int, r0: int, c0: int) -> List[List[int]]:
    ans = [[r0, c0]]
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    i = 0 …

Category: leetcode

Read More

886-Possible-Bipartition

Fri 14 November 2025

https://leetcode.com/problems/possible-bipartition

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


class Color(Enum):
  kWhite = 0
  kRed = 1
  kGreen = 2


class Solution:
  def possibleBipartition(self, n: int, dislikes: List[List[int]]) -> bool:
    graph = [[] for _ in range(n …

Category: leetcode

Read More

888-Fair-Candy-Swap

Fri 14 November 2025

https://leetcode.com/problems/fair-candy-swap

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def fairCandySwap(self, A: List[int], B: List[int]) -> List[int]:
    diff = (sum(A) - sum(B)) // 2
    B = set(B)

    for a in A:
      if a - diff in B …

Category: leetcode

Read More
Page 74 of 146

« Prev Next »