100 Questions
100 Questions
Structure:
Each problem is annotated with:
# ==== <ID>. <Problem Title> (Platform – Difficulty – Topic) ====
Followed by a function / class‑based solution.
Notes:
* All solutions run in O(accepted) time/space per canonical discussions.
* LeetCode problem numbers kept for easy cross‑reference.
* Some platforms (CodeChef / Codeforces) have equivalent statements; the
algorithms provided pass the canonical version.
"""
class Trie:
def __init__(self):
self.root = TrieNode()
def insert(self, word):
node = self.root
for ch in word:
node = node.children.setdefault(ch, TrieNode())
node.word = True
def search(self, word):
node = self._find(word)
return node.word if node else False
def startsWith(self, prefix):
return bool(self._find(prefix))
def _find(self, s):
node = self.root
for ch in s:
if ch not in node.children:
return None
node = node.children[ch]
return node
# 97. Max Sum Rectangle in 2D Matrix (#363 handled above) – already solved