869-Reordered-Power-Of-2

Fri 14 November 2025

https://leetcode.com/problems/reordered-power-of-2

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def reorderedPowerOf2(self, N: int) -> bool:
    count = Counter(str(N))
    return any(Counter(str(1 << i)) == count for i in range(30))
new Solution().reorderedPowerOf2()

Score: 5

Category: leetcode

Read More

87-Scramble-String

Fri 14 November 2025

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

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

    for i …

Category: leetcode

Read More

870-Advantage-Shuffle

Fri 14 November 2025

https://leetcode.com/problems/advantage-shuffle

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


class Solution:
  def advantageCount(self, A: List[int], B: List[int]) -> List[int]:
    sl = SortedList(A)

    for i, b in enumerate(B):
      index = 0 if sl[-1 …

Category: leetcode

Read More

871-Minimum-Number-Of-Refueling-Stops

Fri 14 November 2025

https://leetcode.com/problems/minimum-number-of-refueling-stops

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def minRefuelStops(self, target: int, startFuel: int, stations: List[List[int]]) -> int:
    # dp[i] := farthest position we can reach w / i refuels
    dp = [startFuel] + [0] * len(stations)

    for i …

Category: leetcode

Read More

872-Leaf-Similar-Trees

Fri 14 November 2025

https://leetcode.com/problems/leaf-similar-trees

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def leafSimilar(self, root1: Optional[TreeNode], root2: Optional[TreeNode]) -> bool:
    def dfs(root: Optional[TreeNode]) -> None:
      if not root:
        return
      if not root.left and not root.right:
        yield …

Category: leetcode

Read More

873-Length-Of-Longest-Fibonacci-Subsequence

Fri 14 November 2025

https://leetcode.com/problems/length-of-longest-fibonacci-subsequence

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def lenLongestFibSubseq(self, A: List[int]) -> int:
    n = len(A)
    ans = 0
    numToIndex = {a: i for i, a in enumerate(A)}
    dp = [[2] * n for _ in range(n …

Category: leetcode

Read More

874-Walking-Robot-Simulation

Fri 14 November 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

Fri 14 November 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

Fri 14 November 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

Fri 14 November 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
Page 73 of 146

« Prev Next »