874-Walking-Robot-Simulation

Sat 17 May 2025

https://leetcode.com/problems/walking-robot-simulation

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def robotSim(self, commands: List[int], obstacles: List[List[int]]) -> int:
    dirs = [0, 1, 0, -1, 0]
    ans = 0
    d = 0  # 0 := north, 1 := east, 2 := south, 3 := west …

Category: leetcode

Read More

875-Koko-Eating-Bananas

Sat 17 May 2025

https://leetcode.com/problems/koko-eating-bananas

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def minEatingSpeed(self, piles: List[int], h: int) -> int:
    l = 1
    r = max(piles)

    # Hours to eat all piles with speed m
    def eatHours(m: int) -> int:
      return sum …

Category: leetcode

Read More

876-Middle-Of-The-Linked-List

Sat 17 May 2025

https://leetcode.com/problems/middle-of-the-linked-list

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def middleNode(self, head: ListNode) -> ListNode:
    slow = head
    fast = head

    while fast and fast.next:
      slow = slow.next
      fast = fast.next.next

    return slow
new Solution().middleNode()

Score: 5 …

Category: leetcode

Read More

877-Stone-Game

Sat 17 May 2025

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

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def stoneGame(self, piles: List[int]) -> bool:
    n = len(piles)
    # dp[i][j] := max stones you can get more than your opponent in piles[i..j]
    dp = [[0] * n …

Category: leetcode

Read More

878-Nth-Magical-Number

Sat 17 May 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

Sat 17 May 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

Sat 17 May 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

Sat 17 May 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

Sat 17 May 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

Sat 17 May 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
Page 67 of 77

« Prev Next »