795-Number-Of-Subarrays-With-Bounded-Maximum

Fri 14 November 2025

https://leetcode.com/problems/number-of-subarrays-with-bounded-maximum

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numSubarrayBoundedMax(self, A: List[int], L: int, R: int) -> int:
    ans = 0
    l = -1
    r = -1

    for i, a in enumerate(A):
      if a > R:
        l = i
      if …

Category: leetcode

Read More

797-All-Paths-From-Source-To-Target

Fri 14 November 2025

https://leetcode.com/problems/all-paths-from-source-to-target

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

    def dfs(u: int, path: List[int]) -> None:
      if u == len(graph) - 1:
        ans.append(path)
        return

      for …

Category: leetcode

Read More

8-String-To-Integer-Atoi

Fri 14 November 2025

https://leetcode.com/problems/string-to-integer-atoi

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def myAtoi(self, s: str) -> int:
    s = s.strip()
    if not s:
      return 0

    sign = -1 if s[0] == '-' else 1
    if s[0] in {'-', '+'}:
      s = s[1:]

    num …

Category: leetcode

Read More

80-Remove-Duplicates-From-Sorted-Array-Ii

Fri 14 November 2025

https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii

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

    for num in nums:
      if i < 2 or num != nums[i - 2]:
        nums[i] = num
        i += 1

    return i
new …

Category: leetcode

Read More

801-Minimum-Swaps-To-Make-Sequences-Increasing

Fri 14 November 2025

https://leetcode.com/problems/minimum-swaps-to-make-sequences-increasing

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def minSwap(self, A: List[int], B: List[int]) -> int:
    keepAt = [math.inf] * len(A)
    swapAt = [math.inf] * len(A)
    keepAt[0] = 0
    swapAt[0] = 1

    for i in …

Category: leetcode

Read More

802-Find-Eventual-Safe-States

Fri 14 November 2025

https://leetcode.com/problems/find-eventual-safe-states

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


class State(Enum):
  kInit = 0
  kVisiting = 1
  kVisited = 2


class Solution:
  def eventualSafeNodes(self, graph: List[List[int]]) -> List[int]:
    state = [State.kInit] * len(graph)

    def hasCycle …

Category: leetcode

Read More

804-Unique-Morse-Code-Words

Fri 14 November 2025

https://leetcode.com/problems/unique-morse-code-words

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def uniqueMorseRepresentations(self, words: List[str]) -> int:
    morse = [".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--",
             "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."]
    transformations = set()

    for word in words:
      transformation = ''.join(morse[ord(c) - ord('a')] for c in word)
      transformations.add(transformation)

    return …

Category: leetcode

Read More

805-Split-Array-With-Same-Average

Fri 14 November 2025

https://leetcode.com/problems/split-array-with-same-average

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def splitArraySameAverage(self, A: List[int]) -> bool:
    n = len(A)
    summ = sum(A)
    if not any(i * summ % n == 0 for i in range(1, n // 2 + 1)):
      return …

Category: leetcode

Read More

807-Max-Increase-To-Keep-City-Skyline

Fri 14 November 2025

https://leetcode.com/problems/max-increase-to-keep-city-skyline

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def maxIncreaseKeepingSkyline(self, grid: List[List[int]]) -> int:
    rowMax = list(map(max, grid))
    colMax = list(map(max, zip(*grid)))
    return sum(min(i, j) for i in rowMax for …

Category: leetcode

Read More

808-Soup-Servings

Fri 14 November 2025

https://leetcode.com/problems/soup-servings

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def soupServings(self, N: int) -> float:
    def dfs(a: int, b: int) -> float:
      if a <= 0 and b <= 0:
        return 0.5
      if a <= 0:
        return 1.0
      if …

Category: leetcode

Read More
Page 60 of 77

« Prev Next »