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

809-Expressive-Words

Fri 14 November 2025

https://leetcode.com/problems/expressive-words

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def expressiveWords(self, S: str, words: List[str]) -> int:
    def isStretchy(word: str) -> bool:
      n = len(S)
      m = len(word)

      j = 0
      for i in range(n):
        if j …

Category: leetcode

Read More

81-Search-In-Rotated-Sorted-Array-Ii

Fri 14 November 2025

https://leetcode.com/problems/search-in-rotated-sorted-array-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def search(self, nums: List[int], target: int) -> bool:
    l = 0
    r = len(nums) - 1

    while l <= r:
      m = (l + r) // 2
      if nums[m] == target:
        return True
      if …

Category: leetcode

Read More

810-Chalkboard-Xor-Game

Fri 14 November 2025

https://leetcode.com/problems/chalkboard-xor-game

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def xorGame(self, nums: List[int]) -> bool:
    return functools.reduce(operator.xor, nums) == 0 or len(nums) % 2 == 0
new Solution().xorGame()

Score: 5

Category: leetcode

Read More

811-Subdomain-Visit-Count

Fri 14 November 2025

https://leetcode.com/problems/subdomain-visit-count

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def subdomainVisits(self, cpdomains: List[str]) -> List[str]:
    ans = []
    count = Counter()

    for cpdomain in cpdomains:
      num, domains = cpdomain.split()
      num, domains = int(num), domains.split('.')
      for i in reversed …

Category: leetcode

Read More
Page 67 of 146

« Prev Next »