840-Magic-Squares-In-Grid

Sat 17 May 2025

https://leetcode.com/problems/magic-squares-in-grid

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numMagicSquaresInside(self, grid: List[List[int]]) -> int:
    def isMagic(i: int, j: int) -> int:
      s = "".join(str(grid[i + num // 3][j + num % 3])
                  for num in [0 …

Category: leetcode

Read More

841-Keys-And-Rooms

Sat 17 May 2025

https://leetcode.com/problems/keys-and-rooms

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def canVisitAllRooms(self, rooms: List[List[int]]) -> bool:
    seen = [False] * len(rooms)

    def dfs(node: int) -> None:
      seen[node] = True
      for child in rooms[node]:
        if not seen[child …

Category: leetcode

Read More

843-Guess-The-Word

Sat 17 May 2025

https://leetcode.com/problems/guess-the-word

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
# """
# This is Master's API interface.
# You should not implement it, or speculate about its implementation
# """
# Class Master:
#   def guess(self, word: str) -> int:

class Solution:
  def findSecretWord(self, wordlist: List …

Category: leetcode

Read More

845-Longest-Mountain-In-Array

Sat 17 May 2025

https://leetcode.com/problems/longest-mountain-in-array

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

    while i + 1 < len(A):
      while i + 1 < len(A) and A[i] == A[i + 1]:
        i += 1 …

Category: leetcode

Read More

846-Hand-Of-Straights

Sat 17 May 2025

https://leetcode.com/problems/hand-of-straights

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isNStraightHand(self, hand: List[int], W: int) -> bool:
    count = Counter(hand)

    for start in sorted(count):
      value = count[start]
      if value > 0:
        for i in range(start, start …

Category: leetcode

Read More

847-Shortest-Path-Visiting-All-Nodes

Sat 17 May 2025

https://leetcode.com/problems/shortest-path-visiting-all-nodes

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def shortestPathLength(self, graph: List[List[int]]) -> int:
    n = len(graph)
    goal = (1 << n) - 1

    ans = 0
    q = deque()  # (u, state)
    seen = set()

    for i in range(n):
      q …

Category: leetcode

Read More

848-Shifting-Letters

Sat 17 May 2025

https://leetcode.com/problems/shifting-letters

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

    for i in reversed(range(len(shifts) - 1)):
      shifts[i] += shifts[i + 1]

    for c, shift in zip(s …

Category: leetcode

Read More

849-Maximize-Distance-To-Closest-Person

Sat 17 May 2025

https://leetcode.com/problems/maximize-distance-to-closest-person

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def maxDistToClosest(self, seats: List[int]) -> int:
    n = len(seats)
    ans = 0
    j = -1

    for i in range(n):
      if seats[i] == 1:
        ans = i if j == -1 else …

Category: leetcode

Read More

85-Maximal-Rectangle

Sat 17 May 2025

https://leetcode.com/problems/maximal-rectangle

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def maximalRectangle(self, matrix: List[List[str]]) -> int:
    if not matrix:
      return 0

    ans = 0
    hist = [0] * len(matrix[0])

    def largestRectangleArea(heights: List[int]) -> int:
      ans = 0
      stack …

Category: leetcode

Read More

850-Rectangle-Area-Ii

Sat 17 May 2025

https://leetcode.com/problems/rectangle-area-ii

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

    for x1, y1, x2, y2 in rectangles:
      events.append((x1, y1, y2, 's'))
      events.append((x2, y1, y2, 'e'))

    events …

Category: leetcode

Read More
Page 64 of 77

« Prev Next »