812-Largest-Triangle-Area

Fri 14 November 2025

https://leetcode.com/problems/largest-triangle-area

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

    for Ax, Ay in points:
      for Bx, By in points:
        for Cx, Cy in points:
          ans = max(ans, 0 …

Category: leetcode

Read More

814-Binary-Tree-Pruning

Fri 14 November 2025

https://leetcode.com/problems/binary-tree-pruning

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

Category: leetcode

Read More

815-Bus-Routes

Fri 14 November 2025

https://leetcode.com/problems/bus-routes

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numBusesToDestination(self, routes: List[List[int]], S: int, T: int) -> int:
    if S == T:
      return 0

    graph = defaultdict(list)
    usedBuses = set()

    for i in range(len(routes)):
      for …

Category: leetcode

Read More

816-Ambiguous-Coordinates

Fri 14 November 2025

https://leetcode.com/problems/ambiguous-coordinates

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def ambiguousCoordinates(self, S: str) -> List[str]:
    def splits(S: str) -> List[str]:
      if not S or len(S) > 1 and S[0] == S[-1] == '0':
        return []
      if S …

Category: leetcode

Read More

817-Linked-List-Components

Fri 14 November 2025

https://leetcode.com/problems/linked-list-components

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numComponents(self, head: ListNode, G: List[int]) -> int:
    ans = 0
    G = set(G)

    while head:
      if head.val in G and (head.next == None or head.next.val …

Category: leetcode

Read More

819-Most-Common-Word

Fri 14 November 2025

https://leetcode.com/problems/most-common-word

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def mostCommonWord(self, paragraph: str, banned: List[str]) -> str:
    banned = set(banned)
    words = re.findall(r'\w+', paragraph.lower())
    return Counter(word for word in words if word not …

Category: leetcode

Read More

82-Remove-Duplicates-From-Sorted-List-Ii

Fri 14 November 2025

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

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def deleteDuplicates(self, head: ListNode) -> ListNode:
    dummy = ListNode(0, head)
    prev = dummy

    while head:
      while head.next and head.val == head.next.val:
        head = head.next
      if prev.next …

Category: leetcode

Read More

820-Short-Encoding-Of-Words

Fri 14 November 2025

https://leetcode.com/problems/short-encoding-of-words

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class TrieNode:
  def __init__(self):
    self.children: Dict[str, TrieNode] = defaultdict(TrieNode)
    self.depth = 0


class Solution:
  def minimumLengthEncoding(self, words: List[str]) -> int:
    root = TrieNode()
    leaves = []

    def insert(word: str …

Category: leetcode

Read More

822-Card-Flipping-Game

Fri 14 November 2025

https://leetcode.com/problems/card-flipping-game

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def flipgame(self, fronts: List[int], backs: List[int]) -> int:
    same = {f for f, b in zip(fronts, backs) if f == b}
    return min([num for num in fronts …

Category: leetcode

Read More

823-Binary-Trees-With-Factors

Fri 14 November 2025

https://leetcode.com/problems/binary-trees-with-factors

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numFactoredBinaryTrees(self, arr: List[int]) -> int:
    kMod = 1_000_000_007
    n = len(arr)
    # dp[i] := # Of binary trees with arr[i] as root
    dp = [1] * n
    arr.sort()
    numToIndex …

Category: leetcode

Read More
Page 68 of 146

« Prev Next »