758-Bold-Words-In-String

Sat 17 May 2025

https://leetcode.com/problems/bold-words-in-string

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def boldWords(self, words: List[str], s: str) -> str:
    n = len(s)
    ans = []
    # bold[i] := True if s[i] should be bolded
    bold = [0] * n

    boldEnd = -1  # s[i …

Category: leetcode

Read More

759-Employee-Free-Time

Sat 17 May 2025

https://leetcode.com/problems/employee-free-time

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def employeeFreeTime(self, schedule: '[[Interval]]') -> '[Interval]':
    ans = []
    intervals = []

    for s in schedule:
      intervals.extend(s)

    intervals.sort(key=lambda x: x.start)

    prevEnd = intervals[0].end

    for interval in …

Category: leetcode

Read More

76-Minimum-Window-Substring

Sat 17 May 2025

https://leetcode.com/problems/minimum-window-substring

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def minWindow(self, s: str, t: str) -> str:
    count = Counter(t)
    required = len(t)
    bestLeft = -1
    minLength = len(s) + 1

    l = 0
    for r, c in enumerate(s):
      count …

Category: leetcode

Read More

761-Special-Binary-String

Sat 17 May 2025

https://leetcode.com/problems/special-binary-string

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def makeLargestSpecial(self, S: str) -> str:
    specials = []
    count = 0

    i = 0
    for j, c in enumerate(S):
      count += 1 if c == '1' else -1
      if count == 0:
        specials.append …

Category: leetcode

Read More

763-Partition-Labels

Sat 17 May 2025

https://leetcode.com/problems/partition-labels

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def partitionLabels(self, S: str) -> List[int]:
    ans = []
    letterToRightmostIndex = {c: i for i, c in enumerate(S)}

    l = 0
    r = 0

    for i, c in enumerate(S):
      r = max …

Category: leetcode

Read More

766-Toeplitz-Matrix

Sat 17 May 2025

https://leetcode.com/problems/toeplitz-matrix

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isToeplitzMatrix(self, matrix: List[List[int]]) -> bool:
    for i in range(len(matrix) - 1):
      for j in range(len(matrix[0]) - 1):
        if matrix[i][j] != matrix[i …

Category: leetcode

Read More

767-Reorganize-String

Sat 17 May 2025

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

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def reorganizeString(self, s: str) -> str:
    count = Counter(s)
    if max(count.values()) > (len(s) + 1) // 2:
      return ''

    ans = []
    maxHeap = [(-freq, c) for c, freq in count.items()]
    heapq …

Category: leetcode

Read More

768-Max-Chunks-To-Make-Sorted-Ii

Sat 17 May 2025

https://leetcode.com/problems/max-chunks-to-make-sorted-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def maxChunksToSorted(self, arr: List[int]) -> int:
    n = len(arr)
    ans = 0
    maxi = -math.inf
    mini = [arr[-1]] * n

    for i in reversed(range(n - 1)):
      mini[i] = min …

Category: leetcode

Read More

769-Max-Chunks-To-Make-Sorted

Sat 17 May 2025

https://leetcode.com/problems/max-chunks-to-make-sorted

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def maxChunksToSorted(self, arr: List[int]) -> int:
    ans = 0
    maxi = -math.inf

    for i, a in enumerate(arr):
      maxi = max(maxi, a)
      if maxi == i:
        ans += 1

    return ans …

Category: leetcode

Read More

77-Combinations

Sat 17 May 2025

https://leetcode.com/problems/combinations

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

    def dfs(s: int, path: List[int]) -> None:
      if len(path) == k:
        ans.append(path.copy())
        return

      for …

Category: leetcode

Read More
Page 57 of 77

« Prev Next »