Compare commits

..
Author SHA1 Message Date
Prad Nukala 6c18301aa6 feat(work): add Lowest Common Ancestor of BST solution 2026-09-05 16:33:03 -04:00
Prad Nukala 02f6a20cc1 docs(docs): add documentation for 235 Lowest Common Ancestor of a Binary Search Tree 2026-09-05 16:32:59 -04:00
Prad Nukala 9288aaa152 feat(work): add Kth Smallest Element in a BST solution 2026-09-05 16:28:21 -04:00
Prad Nukala d5ea71dbc1 docs(docs): add MDX page for “230. Kth Smallest Element in a BST” 2026-09-05 16:28:18 -04:00
Prad Nukala 3e1a66eb37 feat(work): add LeetCode solutions for 217, 271, and 98 2026-09-05 13:37:53 -04:00
Prad Nukala 9a2b80949b docs(docs): add 271 Encode/Decode Strings and 98 Validate BST pages 2026-09-05 13:37:42 -04:00
Prad Nukala 883dc69dba docs(docs): update index title from “Progress” to “Overview” 2026-09-04 16:49:23 -04:00
Prad Nukala e3f0b5420a docs(docs): replace index with live progress dashboard and delete redundant progress page 2026-09-04 16:46:50 -04:00
Prad Nukala 987eb7ab5b feat(work): add solution for LeetCode 1448 Count Good Nodes in Binary Tree 2026-09-04 16:44:07 -04:00
Prad Nukala e4118fccd3 docs(docs): add MDX page for LeetCode 1448 Count Good Nodes in Binary Tree problem 2026-09-04 16:44:04 -04:00
Prad Nukala 95db4ca46c feat(work): add solution for Binary Tree Right Side View problem 2026-09-04 11:48:03 -04:00
Prad Nukala 0cc7ca607e docs(docs): add documentation for Binary Tree Right Side View problem 2026-09-04 11:47:59 -04:00
Prad Nukala 71ec39fe34 feat(work): add solution for Binary Tree Level Order Traversal (LC 102) 2026-09-04 11:33:20 -04:00
Prad Nukala 51decd23bd docs(docs): add documentation for Binary Tree Level Order Traversal (LeetCode 102) 2026-09-04 11:33:15 -04:00
Prad Nukala 90082518a6 feat(work): add solution for Lowest Common Ancestor of a Binary Tree 2026-09-03 14:17:54 -04:00
Prad Nukala e10a913546 docs(docs): add 236 Lowest Common Ancestor of a Binary Tree documentation 2026-09-03 14:17:51 -04:00
Prad Nukala fec94ed636 feat(work): add solution for Invert Binary Tree (LC 226) 2026-09-03 14:01:06 -04:00
Prad Nukala 30273d0030 docs(docs): add Invert Binary Tree documentation 2026-09-03 14:01:02 -04:00
Prad Nukala 50299defef feat(work): add Maximum Depth of Binary Tree solution 2026-09-03 13:52:57 -04:00
Prad Nukala c843be855e feat(docs): add Maximum Depth of Binary Tree documentation 2026-09-03 13:52:54 -04:00
Prad Nukala 1e0e03daaa feat(work): add Set Matrix Zeroes solution 2026-09-02 16:52:29 -04:00
Prad Nukala 7b182206dd docs(docs): add documentation for Set Matrix Zeroes problem 2026-09-02 16:52:26 -04:00
Prad Nukala faaaf52f85 feat(work): add Rotate Image and Spiral Matrix solutions 2026-09-02 16:49:41 -04:00
Prad Nukala 090f3d6719 docs(docs): add new problem pages for Rotate Image, Spiral Matrix, and Add Two Numbers 2026-09-02 16:49:39 -04:00
Prad Nukala a3ae16ad96 feat(work): add Group Anagrams solution 2026-09-01 15:56:02 -04:00
Prad Nukala 9faa0b0337 feat(work): implement correct addTwoNumbers algorithm for linked list addition 2026-09-01 14:39:45 -04:00
34 changed files with 1797 additions and 21 deletions

No files matched your search

@@ -42,7 +42,14 @@ flowchart TD
## Solution
```js
<CodeGroup>
```py Python
class Solution:
def containsDuplicate(self, nums: List[int]) -> bool:
```
```js JavaScript
/**
* @param {number[]} nums
* @return {boolean}
@@ -59,6 +66,8 @@ var containsDuplicate = function(nums) {
};
```
</CodeGroup>
## Explanation
<YouTube id="3OamzN90kPg" title="Contains Duplicate - Leetcode 217 - Python" />
@@ -0,0 +1,48 @@
---
title: '271. Encode and Decode Strings'
description: Design an algorithm to encode a list of strings to a string. The encoded string is then sent over the network and is decoded back to the original list of strings
sidebar:
label: 'Encode and Decode Strings'
badge: 'Medium'
---
<Badge variant="accent">Array</Badge>
::::warning
Could you write a generalized algorithm to work on any possible set of characters?
::::
### Example 1:
- Input: `dummy_input = ["Hello","World"]`
- Output: `["Hello","World"]`
- Explanation: Machine `1`: Codec encoder = new Codec(); String msg = encoder.encode(strs); Machine `1` ---msg---> Machine `2` Machine `2`: Codec decoder = new Codec(); `String[] strs` = decoder.decode(msg);
### Example 2:
- Input: `dummy_input = [""]`
- Output: `[""]`
### Constraints:
- `1 <= strs.length <= 200`
- `0 <= strs[i].length <= 200`
- `strs[i]` contains any possible characters out of 256 valid ASCII characters.
## Solution
```py
class Codec:
def encode(self, strs: List[str]) -> str:
"""Encodes a list of strings to a single string.
"""
def decode(self, s: str) -> List[str]:
"""Decodes a single string to a list of strings.
"""
# Your Codec object will be instantiated and called as such:
# codec = Codec()
# codec.decode(codec.encode(strs))
```
@@ -0,0 +1,37 @@
---
title: '48. Rotate Image'
description: You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise)
sidebar:
label: 'Rotate Image'
badge: 'Medium'
---
<Badge variant="accent">Matrix Index Math</Badge>
### Example 1:
- Input: `matrix = [[1,2,3],[4,5,6],[7,8,9]]`
- Output: `[[7,4,1],[8,5,2],[9,6,3]]`
### Example 2:
- Input: `matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]`
- Output: `[[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]`
### Constraints:
- `n == matrix.length == matrix[i].length`
- `1 <= n <= 20`
- `-1000 <= matrix[i][j] <= 1000`
## Solution
```py
class Solution:
def rotate(self, matrix: List[List[int]]) -> None:
n = len(matrix)
for r in range(n):
for c in range(r + 1, n):
matrix[r][c], matrix[c][r] = matrix[c][r], matrix[r][c]
for r in range(n):
matrix[r].reverse()
```
@@ -0,0 +1,59 @@
---
title: '54. Spiral Matrix'
description: Given an m x n matrix, return all elements of the matrix in spiral order
sidebar:
label: 'Spiral Matrix'
badge: 'Medium'
---
<Badge variant="accent">Matrix Index Math</Badge>
### Example 1:
- Input: `matrix = [[1,2,3],[4,5,6],[7,8,9]]`
- Output: `[1,2,3,6,9,8,7,4,5]`
### Example 2:
- Input: `matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]`
- Output: `[1,2,3,4,8,12,11,10,9,5,6,7]`
### Constraints:
- `m == matrix.length`
- `n == matrix[i].length`
- `1 <= m, n <= 10`
- `-100 <= matrix[i][j] <= 100`
## Solution
```py
class Solution:
def spiralOrder(self, matrix: List[List[int]]) -> List[int]:
res = []
top, bottom = 0, len(matrix) - 1
left, right = 0, len(matrix[0]) - 1
while top <= bottom and left <= right:
# 1. Top Row
for c in range(left, right + 1):
res.append(matrix[top][c])
top += 1
# 2. Right Column
for r in range(top, bottom + 1):
res.append(matrix[r][right])
right -= 1
# 3. Bottom Row
if top <= bottom:
for c in range(right, left - 1, -1):
res.append(matrix[bottom][c])
bottom -= 1
# 4. Left Column
if left <= right:
for r in range(bottom, top - 1, -1):
res.append(matrix[r][left])
left += 1
return res
```
@@ -0,0 +1,67 @@
---
title: '73. Set Matrix Zeroes'
description: Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's
sidebar:
label: 'Set Matrix Zeroes'
badge: 'Medium'
---
<Badge variant="accent">Matrix Index Math</Badge>
::::warning
You must do it in place.
::::
### Example 1:
- Input: `matrix = [[1,1,1],[1,0,1],[1,1,1]]`
- Output: `[[1,0,1],[0,0,0],[1,0,1]]`
### Example 2:
- Input: `matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]`
- Output: `[[0,0,0,0],[0,4,5,0],[0,3,1,0]]`
### Constraints:
- `m == matrix.length`
- `n == matrix[0].length`
- `1 <= m, n <= 200`
- `-2^31 <= matrix[i][j] <= 2^31 - 1`
- A straightforward solution using O(mn) space is probably a bad idea.
- A simple improvement uses O(m + n) space, but still not the best solution.
- Could you devise a constant space solution?
## Solution
```py
class Solution:
def setZeroes(self, matrix: List[List[int]]) -> None:
"""
Do not return anything, modify matrix in-place instead.
"""
m, n = len(matrix), len(matrix[0])
# 1. remember if row 0 or column 0 have their own zeros
row0_zero = any(matrix[0][c] == 0 for c in range(n))
col0_zero = any(matrix[r][0] == 0 for r in range(m))
# 2. use row 0 and column 0 as marker lists
for r in range(1, m):
for c in range(1, n):
if matrix[r][c] == 0:
matrix[r][0] = 0
matrix[0][c] = 0
# 3. zero the inner cells from the markers
for r in range(1, m):
for c in range(1, n):
if matrix[r][0] == 0 or matrix[0][c] == 0:
matrix[r][c] = 0
# 4. handle row 0 and column 0 last
if row0_zero:
for c in range(n):
matrix[0][c] = 0
if col0_zero:
for r in range(m):
matrix[r][0] = 0
```
@@ -0,0 +1,57 @@
---
title: '2. Add Two Numbers'
description: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list
sidebar:
label: 'Add Two Numbers'
badge: 'Medium'
---
<Badge variant="accent">Hybrid Structures</Badge>
### Example 1:
- Input: `l1 = [2,4,3], l2 = [5,6,4]`
- Output: `[7,0,8]`
- Explanation: `342 + 465 = 807`.
### Example 2:
- Input: `l1 = [0], l2 = [0]`
- Output: `[0]`
### Example 3:
- Input: `l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]`
- Output: `[8,9,9,9,0,0,0,1]`
### Constraints:
- The number of nodes in each linked list is in the range [1, 100].
- `0 <= Node.val <= 9`
- It is guaranteed that the list represents a number that does not have leading zeros.
## Solution
```py
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def addTwoNumbers(
self, l1: Optional[ListNode], l2: Optional[ListNode]
) -> Optional[ListNode]:
dummy = ListNode()
carry = 0
curr = dummy
while l1 or l2 or carry:
s = (l1.val if l1 else 0) + (l2.val if l2 else 0) + carry
carry, val = divmod(s, 10)
curr.next = ListNode(val)
curr = curr.next
l1 = l1.next if l1 else None
l2 = l2.next if l2 else None
return dummy.next
```
@@ -0,0 +1,61 @@
---
title: '102. Binary Tree Level Order Traversal'
description: Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level)
sidebar:
label: 'Binary Tree Level Order Traversal'
badge: 'Medium'
---
<Badge variant="accent">Tree BFS</Badge>
### Example 1:
- Input: `root = [3,9,20,null,null,15,7]`
- Output: `[[3],[9,20],[15,7]]`
### Example 2:
- Input: `root = [1]`
- Output: `[[1]]`
### Example 3:
- Input: `root = []`
- Output: `[]`
### Constraints:
- The number of nodes in the tree is in the range [0, 2000].
- `-1000 <= Node.val <= 1000`
## Solution
```py
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
from collections import deque
class Solution:
# T: O(n) S: O(n)
def levelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:
res = []
q = deque()
q.append(root)
while q:
qLen = len(q)
level = []
for i in range(qLen):
node = q.popleft()
if node:
level.append(node.val)
q.append(node.left)
q.append(node.right)
if level:
res.append(level)
return res
```
@@ -0,0 +1,39 @@
---
title: '104. Maximum Depth of Binary Tree'
description: Given the root of a binary tree, return its maximum depth
sidebar:
label: 'Maximum Depth of Binary Tree'
badge: 'Easy'
---
<Badge variant="accent">Tree DFS</Badge>
### Example 1:
- Input: `root = [3,9,20,null,null,15,7]`
- Output: `3`
### Example 2:
- Input: `root = [1,null,2]`
- Output: `2`
### Constraints:
- The number of nodes in the tree is in the range [0, 10^4].
- `-100 <= Node.val <= 100`
## Solution
```py
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def maxDepth(self, root: Optional[TreeNode]) -> int:
if not root:
return 0
return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right))
```
@@ -0,0 +1,52 @@
---
title: '1448. Count Good Nodes in Binary Tree'
description: Given a binary tree root, a node X in the tree is named good if in the path from root to X there are no nodes with a value greater than X
sidebar:
label: 'Count Good Nodes in Binary Tree'
badge: 'Medium'
---
<Badge variant="accent">Tree BFS</Badge>
### Example 1:
- Input: `root = [3,1,4,3,null,1,5]`
- Output: `4`
- Explanation: Nodes in blue are good. Root Node `(3`) is always a good node. Node `4` -> (3,4) is the maximum value in the path starting from the `root`. Node `5` -> (3,4,5) is the maximum value in the path Node `3` -> (3,1,3) is the maximum value in the path.
### Example 2:
- Input: `root = [3,3,null,4,2]`
- Output: `3`
- Explanation: Node `2` -> `(3`, `3`, `2`) is not good, because `"3`" is higher than it.
### Example 3:
- Input: `root = [1]`
- Output: `1`
- Explanation: Root is considered as good.
### Constraints:
- The number of nodes in the binary tree is in the range [1, 10^5].
- Each node's value is between [-10^4, 10^4].
## Solution
```py
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def goodNodes(self, root: TreeNode) -> int:
def dfs(node, max_val):
if not node:
return 0
is_good = 1 if node.val >= max_val else 0
new_max = max(max_val, node.val)
return is_good + dfs(node.left, new_max) + dfs(node.right, new_max)
return dfs(root, root.val)
```
@@ -0,0 +1,64 @@
---
title: '199. Binary Tree Right Side View'
description: Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom
sidebar:
label: 'Binary Tree Right Side View'
badge: 'Medium'
---
<Badge variant="accent">Tree BFS</Badge>
### Example 1:
- Input: `root = [1,2,3,null,5,null,4]`
- Output: `[1,3,4]`
### Example 2:
- Input: `root = [1,2,3,4,null,null,null,5]`
- Output: `[1,3,4,5]`
### Example 3:
- Input: `root = [1,null,3]`
- Output: `[1,3]`
### Example 4:
- Input: `root = []`
- Output: `[]`
### Constraints:
- The number of nodes in the tree is in the range [0, 100].
- `-100 <= Node.val <= 100`
## Solution
```py
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
from collections import deque
class Solution:
def rightSideView(self, root: Optional[TreeNode]) -> List[int]:
res = []
q = deque([root])
while q:
rightSide = None
qLen = len(q)
for i in range(qLen):
node = q.popleft()
if node:
rightSide = node
q.append(node.left)
q.append(node.right)
if rightSide:
res.append(rightSide.val)
return res
```
@@ -0,0 +1,49 @@
---
title: '226. Invert Binary Tree'
description: Given the root of a binary tree, invert the tree, and return its root
sidebar:
label: 'Invert Binary Tree'
badge: 'Easy'
---
<Badge variant="accent">Tree DFS</Badge>
### Example 1:
- Input: `root = [4,2,7,1,3,6,9]`
- Output: `[4,7,2,9,6,3,1]`
### Example 2:
- Input: `root = [2,1,3]`
- Output: `[2,3,1]`
### Example 3:
- Input: `root = []`
- Output: `[]`
### Constraints:
- The number of nodes in the tree is in the range [0, 100].
- `-100 <= Node.val <= 100`
## Solution
```py
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]:
if not root:
return None
left = self.invertTree(root.left)
right = self.invertTree(root.right)
root.left = right
root.right = left
return root
```
@@ -0,0 +1,54 @@
---
title: '230. Kth Smallest Element in a BST'
description: Given the root of a binary search tree, and an integer k, return the k^th smallest value (1-indexed) of all the values of the nodes in the tree
sidebar:
label: 'Kth Smallest Element in a BST'
badge: 'Medium'
---
<Badge variant="accent">Binary Search Tree</Badge>
::::warning
If the BST is modified often (i.e., we can do insert and delete operations) and you need to find the kth smallest frequently, how would you optimize?
::::
### Example 1:
- Input: `root = [3,1,4,null,2], k = 1`
- Output: `1`
### Example 2:
- Input: `root = [5,3,6,2,4,null,null,1], k = 3`
- Output: `3`
### Constraints:
- The number of nodes in the tree is n.
- `1 <= k <= n <= 10^4`
- `0 <= Node.val <= 10^4`
## Solution
```py
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def kthSmallest(self, root: Optional[TreeNode], k: int) -> int:
n = 0
stack = []
cur = root
while cur or stack:
while cur:
stack.append(cur)
cur = cur.left
cur = stack.pop()
n += 1
if n == k:
return cur.val
cur = cur.right
```
@@ -0,0 +1,56 @@
---
title: '235. Lowest Common Ancestor of a Binary Search Tree'
description: Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST
sidebar:
label: 'Lowest Common Ancestor of a Binary Search Tree'
badge: 'Medium'
---
<Badge variant="accent">Binary Search Tree</Badge>
### Example 1:
- Input: `root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 8`
- Output: `6`
- Explanation: The LCA of nodes `2` and `8` is `6`.
### Example 2:
- Input: `root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 4`
- Output: `2`
- Explanation: The LCA of nodes `2` and `4` is `2`, since a node can be a descendant of itself according to the LCA definition.
### Example 3:
- Input: `root = [2,1], p = 2, q = 1`
- Output: `2`
### Constraints:
- The number of nodes in the tree is in the range [2, 10^5].
- `-10^9 <= Node.val <= 10^9`
- All Node.val are unique.
- `p != q`
- p and q will exist in the BST.
## Solution
```py
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def lowestCommonAncestor(
self, root: "TreeNode", p: "TreeNode", q: "TreeNode"
) -> "TreeNode":
cur = root
while cur:
if p.val < cur.val and q.val < cur.val:
cur = cur.left
elif p.val > cur.val and q.val > cur.val:
cur = cur.right
else:
return cur
```
@@ -0,0 +1,62 @@
---
title: '236. Lowest Common Ancestor of a Binary Tree'
description: Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree
sidebar:
label: 'Lowest Common Ancestor of a Binary Tree'
badge: 'Medium'
---
<Badge variant="accent">Tree DFS</Badge>
### Example 1:
- Input: `root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1`
- Output: `3`
- Explanation: The LCA of nodes `5` and `1` is `3`.
### Example 2:
- Input: `root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4`
- Output: `5`
- Explanation: The LCA of nodes `5` and `4` is `5`, since a node can be a descendant of itself according to the LCA definition.
### Example 3:
- Input: `root = [1,2], p = 1, q = 2`
- Output: `1`
### Constraints:
- The number of nodes in the tree is in the range [2, 10^5].
- `-10^9 <= Node.val <= 10^9`
- All Node.val are unique.
- `p != q`
- p and q will exist in the tree.
## Solution
```py
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def lowestCommonAncestor(
self, root: "TreeNode", p: "TreeNode", q: "TreeNode"
) -> "TreeNode":
if not root:
return None
if root == p or root == q:
return root
l = self.lowestCommonAncestor(root.left, p, q)
r = self.lowestCommonAncestor(root.right, p, q)
if l and r:
return root
else:
return l or r
```
@@ -0,0 +1,46 @@
---
title: '98. Validate Binary Search Tree'
description: Given the root of a binary tree, determine if it is a valid binary search tree (BST)
sidebar:
label: 'Validate Binary Search Tree'
badge: 'Medium'
---
<Badge variant="accent">Binary Search Tree</Badge>
### Example 1:
- Input: `root = [2,1,3]`
- Output: `true`
### Example 2:
- Input: `root = [5,1,4,null,null,3,6]`
- Output: `false`
- Explanation: The `root` node's value is `5` but its right child's value is `4`.
### Constraints:
- The number of nodes in the tree is in the range [1, 10^4].
- `-2^31 <= Node.val <= 2^31 - 1`
## Solution
```py
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def isValidBST(self, root: Optional[TreeNode]) -> bool:
def valid(node, low, high):
if not node:
return True
if not (low < node.val < high):
return False
return valid(node.left, low, node.val) and valid(node.right, node.val, high)
return valid(root, float("-inf"), float("inf"))
```
+5 -6
View File
@@ -1,12 +1,11 @@
---
title: Introduction
description: Welcome to your new Blume docs.
title: Overview
description: Live SRS campaign dashboard — phases, ladder, review queue, gates, and recent attempts, fetched from the SRS Worker.
---
## Getting Started
![Dependency Map](../public/dependency-spine.svg)
Welcome to **Blume** — markdown-first docs powered by Astro and Vite.
Live view of the 56-day campaign. Everything below is fetched client-side
from the SRS Worker, so it is always current — no rebuild required.
Edit `docs/index.mdx` to get started, then run `blume dev`.
<ProgressDashboard />
-9
View File
@@ -1,9 +0,0 @@
---
title: Progress
description: Live SRS campaign dashboard — phases, ladder, review queue, gates, and recent attempts, fetched from the SRS Worker.
---
Live view of the 56-day campaign. Everything below is fetched client-side
from the SRS Worker, so it is always current — no rebuild required.
<ProgressDashboard />
+4
View File
@@ -1,3 +1,7 @@
---
hidden: true
---
# todo — draining the review backlog
every solution in `work/1` owes a blind re-solve at `work/3` and a second one at `work/7`. both buckets are empty, so 36 problems owe 72 re-solves and not one has been started. snapshot: `reviewqueues("2026-08-31")` from `apps/cli/work.ts` — what `bun run pick` shows — cross-checked against `/api/stats`.
@@ -0,0 +1,51 @@
"""
217. Contains Duplicate
Difficulty: Easy
https://leetcode.com/problems/contains-duplicate/
──────────────────────────────────────────────────
Given an integer array nums, return true if any value appears at
least twice in the array, and return false if every element is
distinct.
Example 1:
Input: nums = [1,2,3,1]
Output: true
Explanation:
The element 1 occurs at the indices 0 and 3.
Example 2:
Input: nums = [1,2,3,4]
Output: false
Explanation:
All elements are distinct.
Example 3:
Input: nums = [1,1,1,3,3,4,3,2,4,2]
Output: true
Constraints:
• 1 <= nums.length <= 10^5
• -10^9 <= nums[i] <= 10^9
"""
class Solution:
def containsDuplicate(self, nums: List[int]) -> bool:
@@ -0,0 +1,46 @@
"""
104. Maximum Depth of Binary Tree
Difficulty: Easy
https://leetcode.com/problems/maximum-depth-of-binary-tree/
──────────────────────────────────────────────────
Given the root of a binary tree, return its maximum depth.
A binary tree's maximum depth is the number of nodes along the
longest path from the root node down to the farthest leaf node.
Example 1:
Input: root = [3,9,20,null,null,15,7]
Output: 3
Example 2:
Input: root = [1,null,2]
Output: 2
Constraints:
• The number of nodes in the tree is in the range [0, 10^4].
• -100 <= Node.val <= 100
"""
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def maxDepth(self, root: Optional[TreeNode]) -> int:
if not root:
return 0
return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right))
@@ -0,0 +1,54 @@
"""
226. Invert Binary Tree
Difficulty: Easy
https://leetcode.com/problems/invert-binary-tree/
──────────────────────────────────────────────────
Given the root of a binary tree, invert the tree, and return its root.
Example 1:
Input: root = [4,2,7,1,3,6,9]
Output: [4,7,2,9,6,3,1]
Example 2:
Input: root = [2,1,3]
Output: [2,3,1]
Example 3:
Input: root = []
Output: []
Constraints:
• The number of nodes in the tree is in the range [0, 100].
• -100 <= Node.val <= 100
"""
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]:
if not root:
return None
left = self.invertTree(root.left)
right = self.invertTree(root.right)
root.left = right
root.right = left
return root
@@ -0,0 +1,92 @@
"""
271. Encode and Decode Strings
Difficulty: Medium
https://leetcode.com/problems/encode-and-decode-strings/
──────────────────────────────────────────────────
Design an algorithm to encode a list of strings to a string. The
encoded string is then sent over the network and is decoded back to
the original list of strings.
Machine 1 (sender) has the function:
string encode(vector<string> strs) {
// ... your code
return encoded_string;
}
Machine 2 (receiver) has the function:
vector<string> decode(string s) {
//... your code
return strs;
}
So Machine 1 does:
string encoded_string = encode(strs);
and Machine 2 does:
vector<string> strs2 = decode(encoded_string);
strs2 in Machine 2 should be the same as strs in Machine 1.
Implement the encode and decode methods.
You are not allowed to solve the problem using any serialize methods
(such as eval).
Example 1:
Input: dummy_input = ["Hello","World"]
Output: ["Hello","World"]
Explanation:
Machine 1:
Codec encoder = new Codec();
String msg = encoder.encode(strs);
Machine 1 ---msg---> Machine 2
Machine 2:
Codec decoder = new Codec();
String[] strs = decoder.decode(msg);
Example 2:
Input: dummy_input = [""]
Output: [""]
Constraints:
• 1 <= strs.length <= 200
• 0 <= strs[i].length <= 200
• strs[i] contains any possible characters out of 256 valid ASCII
characters.
Follow up: Could you write a generalized algorithm to work on any
possible set of characters?
"""
class Codec:
def encode(self, strs: List[str]) -> str:
"""Encodes a list of strings to a single string.
"""
def decode(self, s: str) -> List[str]:
"""Decodes a single string to a list of strings.
"""
# Your Codec object will be instantiated and called as such:
# codec = Codec()
# codec.decode(codec.encode(strs))
+47
View File
@@ -0,0 +1,47 @@
"""
48. Rotate Image
Difficulty: Medium
https://leetcode.com/problems/rotate-image/
──────────────────────────────────────────────────
You are given an n x n 2D matrix representing an image, rotate the
image by 90 degrees (clockwise).
You have to rotate the image in-place, which means you have to modify
the input 2D matrix directly. DO NOT allocate another 2D matrix and do
the rotation.
Example 1:
Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]
Output: [[7,4,1],[8,5,2],[9,6,3]]
Example 2:
Input: matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]
Output: [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]
Constraints:
• n == matrix.length == matrix[i].length
• 1 <= n <= 20
• -1000 <= matrix[i][j] <= 1000
"""
class Solution:
def rotate(self, matrix: List[List[int]]) -> None:
n = len(matrix)
for r in range(n):
for c in range(r + 1, n):
matrix[r][c], matrix[c][r] = matrix[c][r], matrix[r][c]
for r in range(n):
matrix[r].reverse()
+66
View File
@@ -0,0 +1,66 @@
"""
54. Spiral Matrix
Difficulty: Medium
https://leetcode.com/problems/spiral-matrix/
──────────────────────────────────────────────────
Given an m x n matrix, return all elements of the matrix in spiral
order.
Example 1:
Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]
Output: [1,2,3,6,9,8,7,4,5]
Example 2:
Input: matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]
Output: [1,2,3,4,8,12,11,10,9,5,6,7]
Constraints:
• m == matrix.length
• n == matrix[i].length
• 1 <= m, n <= 10
• -100 <= matrix[i][j] <= 100
"""
class Solution:
def spiralOrder(self, matrix: List[List[int]]) -> List[int]:
res = []
top, bottom = 0, len(matrix) - 1
left, right = 0, len(matrix[0]) - 1
while top <= bottom and left <= right:
# 1. Top Row
for c in range(left, right + 1):
res.append(matrix[top][c])
top += 1
# 2. Right Column
for r in range(top, bottom + 1):
res.append(matrix[r][right])
right -= 1
# 3. Bottom Row
if top <= bottom:
for c in range(right, left - 1, -1):
res.append(matrix[bottom][c])
bottom -= 1
# 4. Left Column
if left <= right:
for r in range(bottom, top - 1, -1):
res.append(matrix[r][left])
left += 1
return res
@@ -0,0 +1,81 @@
"""
73. Set Matrix Zeroes
Difficulty: Medium
https://leetcode.com/problems/set-matrix-zeroes/
──────────────────────────────────────────────────
Given an m x n integer matrix matrix, if an element is 0, set its
entire row and column to 0's.
You must do it in place.
Example 1:
Input: matrix = [[1,1,1],[1,0,1],[1,1,1]]
Output: [[1,0,1],[0,0,0],[1,0,1]]
Example 2:
Input: matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]
Output: [[0,0,0,0],[0,4,5,0],[0,3,1,0]]
Constraints:
• m == matrix.length
• n == matrix[0].length
• 1 <= m, n <= 200
• -2^31 <= matrix[i][j] <= 2^31 - 1
Follow up:
• A straightforward solution using O(mn) space is probably a bad
idea.
• A simple improvement uses O(m + n) space, but still not the best
solution.
• Could you devise a constant space solution?
"""
class Solution:
def setZeroes(self, matrix: List[List[int]]) -> None:
"""
Do not return anything, modify matrix in-place instead.
"""
m, n = len(matrix), len(matrix[0])
# 1. remember if row 0 or column 0 have their own zeros
row0_zero = any(matrix[0][c] == 0 for c in range(n))
col0_zero = any(matrix[r][0] == 0 for r in range(m))
# 2. use row 0 and column 0 as marker lists
for r in range(1, m):
for c in range(1, n):
if matrix[r][c] == 0:
matrix[r][0] = 0
matrix[0][c] = 0
# 3. zero the inner cells from the markers
for r in range(1, m):
for c in range(1, n):
if matrix[r][0] == 0 or matrix[0][c] == 0:
matrix[r][c] = 0
# 4. handle row 0 and column 0 last
if row0_zero:
for c in range(n):
matrix[0][c] = 0
if col0_zero:
for r in range(m):
matrix[r][0] = 0
+14 -5
View File
@@ -53,9 +53,18 @@ class Solution:
def addTwoNumbers(
self, l1: Optional[ListNode], l2: Optional[ListNode]
) -> Optional[ListNode]:
head = ListNode()
dummy = ListNode()
carry = 0
l1curr = head
l2curr = head
while head:
l1.val + l2.val
curr = dummy
while l1 or l2 or carry:
s = (l1.val if l1 else 0) + (l2.val if l2 else 0) + carry
carry, val = divmod(s, 10)
curr.next = ListNode(val)
curr = curr.next
l1 = l1.next if l1 else None
l2 = l2.next if l2 else None
return dummy.next
@@ -0,0 +1,66 @@
"""
102. Binary Tree Level Order Traversal
Difficulty: Medium
https://leetcode.com/problems/binary-tree-level-order-traversal/
──────────────────────────────────────────────────
Given the root of a binary tree, return the level order traversal of
its nodes' values. (i.e., from left to right, level by level).
Example 1:
Input: root = [3,9,20,null,null,15,7]
Output: [[3],[9,20],[15,7]]
Example 2:
Input: root = [1]
Output: [[1]]
Example 3:
Input: root = []
Output: []
Constraints:
• The number of nodes in the tree is in the range [0, 2000].
• -1000 <= Node.val <= 1000
"""
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
from collections import deque
class Solution:
# T: O(n) S: O(n)
def levelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:
res = []
q = deque()
q.append(root)
while q:
qLen = len(q)
level = []
for i in range(qLen):
node = q.popleft()
if node:
level.append(node.val)
q.append(node.left)
q.append(node.right)
if level:
res.append(level)
return res
@@ -0,0 +1,94 @@
"""
1448. Count Good Nodes in Binary Tree
Difficulty: Medium
https://leetcode.com/problems/count-good-nodes-in-binary-tree/
──────────────────────────────────────────────────
Given a binary tree root, a node X in the tree is named good if in
the path from root to X there are no nodes with a value greater than
X.
Return the number of good nodes in the binary tree.
Example 1:
Input: root = [3,1,4,3,null,1,5]
Output: 4
Explanation: Nodes in blue are good.
Root Node (3) is always a good node.
Node 4 -> (3,4) is the maximum value in the path starting from the
root.
Node 5 -> (3,4,5) is the maximum value in the path
Node 3 -> (3,1,3) is the maximum value in the path.
Example 2:
Input: root = [3,3,null,4,2]
Output: 3
Explanation: Node 2 -> (3, 3, 2) is not good, because "3" is higher
than it.
Example 3:
Input: root = [1]
Output: 1
Explanation: Root is considered as good.
Constraints:
• The number of nodes in the binary tree is in the range [1, 10^5].
• Each node's value is between [-10^4, 10^4].
"""
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def goodNodes(self, root: TreeNode) -> int:
def dfs(node, max_val):
if not node:
return 0
is_good = 1 if node.val >= max_val else 0
new_max = max(max_val, node.val)
return is_good + dfs(node.left, new_max) + dfs(node.right, new_max)
return dfs(root, root.val)
@@ -0,0 +1,79 @@
"""
199. Binary Tree Right Side View
Difficulty: Medium
https://leetcode.com/problems/binary-tree-right-side-view/
──────────────────────────────────────────────────
Given the root of a binary tree, imagine yourself standing on the
right side of it, return the values of the nodes you can see ordered
from top to bottom.
Example 1:
Input: root = [1,2,3,null,5,null,4]
Output: [1,3,4]
Explanation:
Example 2:
Input: root = [1,2,3,4,null,null,null,5]
Output: [1,3,4,5]
Explanation:
Example 3:
Input: root = [1,null,3]
Output: [1,3]
Example 4:
Input: root = []
Output: []
Constraints:
• The number of nodes in the tree is in the range [0, 100].
• -100 <= Node.val <= 100
"""
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
from collections import deque
class Solution:
def rightSideView(self, root: Optional[TreeNode]) -> List[int]:
res = []
q = deque([root])
while q:
rightSide = None
qLen = len(q)
for i in range(qLen):
node = q.popleft()
if node:
rightSide = node
q.append(node.left)
q.append(node.right)
if rightSide:
res.append(rightSide.val)
return res
@@ -0,0 +1,63 @@
"""
230. Kth Smallest Element in a BST
Difficulty: Medium
https://leetcode.com/problems/kth-smallest-element-in-a-bst/
──────────────────────────────────────────────────
Given the root of a binary search tree, and an integer k, return the
k^th smallest value (1-indexed) of all the values of the nodes in the
tree.
Example 1:
Input: root = [3,1,4,null,2], k = 1
Output: 1
Example 2:
Input: root = [5,3,6,2,4,null,null,1], k = 3
Output: 3
Constraints:
• The number of nodes in the tree is n.
• 1 <= k <= n <= 10^4
• 0 <= Node.val <= 10^4
Follow up: If the BST is modified often (i.e., we can do insert and
delete operations) and you need to find the kth smallest frequently,
how would you optimize?
"""
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def kthSmallest(self, root: Optional[TreeNode], k: int) -> int:
n = 0
stack = []
cur = root
while cur or stack:
while cur:
stack.append(cur)
cur = cur.left
cur = stack.pop()
n += 1
if n == k:
return cur.val
cur = cur.right
@@ -0,0 +1,70 @@
"""
235. Lowest Common Ancestor of a Binary Search Tree
Difficulty: Medium
https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/
──────────────────────────────────────────────────
Given a binary search tree (BST), find the lowest common ancestor
(LCA) node of two given nodes in the BST.
According to the definition of LCA on Wikipedia: &ldquo;The lowest
common ancestor is defined between two nodes p and q as the lowest
node in T that has both p and q as descendants (where we allow a node
to be a descendant of itself).&rdquo;
Example 1:
Input: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 8
Output: 6
Explanation: The LCA of nodes 2 and 8 is 6.
Example 2:
Input: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 4
Output: 2
Explanation: The LCA of nodes 2 and 4 is 2, since a node can be a
descendant of itself according to the LCA definition.
Example 3:
Input: root = [2,1], p = 2, q = 1
Output: 2
Constraints:
• The number of nodes in the tree is in the range [2, 10^5].
• -10^9 <= Node.val <= 10^9
• All Node.val are unique.
• p != q
• p and q will exist in the BST.
"""
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def lowestCommonAncestor(
self, root: "TreeNode", p: "TreeNode", q: "TreeNode"
) -> "TreeNode":
cur = root
while cur:
if p.val < cur.val and q.val < cur.val:
cur = cur.left
elif p.val > cur.val and q.val > cur.val:
cur = cur.right
else:
return cur
@@ -0,0 +1,76 @@
"""
236. Lowest Common Ancestor of a Binary Tree
Difficulty: Medium
https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/
──────────────────────────────────────────────────
Given a binary tree, find the lowest common ancestor (LCA) of two
given nodes in the tree.
According to the definition of LCA on Wikipedia: &ldquo;The lowest
common ancestor is defined between two nodes p and q as the lowest
node in T that has both p and q as descendants (where we allow a node
to be a descendant of itself).&rdquo;
Example 1:
Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1
Output: 3
Explanation: The LCA of nodes 5 and 1 is 3.
Example 2:
Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4
Output: 5
Explanation: The LCA of nodes 5 and 4 is 5, since a node can be a
descendant of itself according to the LCA definition.
Example 3:
Input: root = [1,2], p = 1, q = 2
Output: 1
Constraints:
• The number of nodes in the tree is in the range [2, 10^5].
• -10^9 <= Node.val <= 10^9
• All Node.val are unique.
• p != q
• p and q will exist in the tree.
"""
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def lowestCommonAncestor(
self, root: "TreeNode", p: "TreeNode", q: "TreeNode"
) -> "TreeNode":
if not root:
return None
if root == p or root == q:
return root
l = self.lowestCommonAncestor(root.left, p, q)
r = self.lowestCommonAncestor(root.right, p, q)
if l and r:
return root
else:
return l or r
@@ -0,0 +1,62 @@
"""
98. Validate Binary Search Tree
Difficulty: Medium
https://leetcode.com/problems/validate-binary-search-tree/
──────────────────────────────────────────────────
Given the root of a binary tree, determine if it is a valid binary
search tree (BST).
A valid BST is defined as follows:
• The left subtree of a node contains only nodes with keys strictly
less than the node's key.
• The right subtree of a node contains only nodes with keys strictly
greater than the node's key.
• Both the left and right subtrees must also be binary search trees.
Example 1:
Input: root = [2,1,3]
Output: true
Example 2:
Input: root = [5,1,4,null,null,3,6]
Output: false
Explanation: The root node's value is 5 but its right child's value
is 4.
Constraints:
• The number of nodes in the tree is in the range [1, 10^4].
• -2^31 <= Node.val <= 2^31 - 1
"""
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def isValidBST(self, root: Optional[TreeNode]) -> bool:
def valid(node, low, high):
if not node:
return True
if not (low < node.val < high):
return False
return valid(node.left, low, node.val) and valid(node.right, node.val, high)
return valid(root, float("-inf"), float("inf"))
+66
View File
@@ -0,0 +1,66 @@
"""
49. Group Anagrams
Difficulty: Medium
https://leetcode.com/problems/group-anagrams/
──────────────────────────────────────────────────
Given an array of strings strs, group the anagrams together. You can
return the answer in any order.
Example 1:
Input: strs = ["eat","tea","tan","ate","nat","bat"]
Output: [["bat"],["nat","tan"],["ate","eat","tea"]]
Explanation:
• There is no string in strs that can be rearranged to form "bat".
• The strings "nat" and "tan" are anagrams as they can be rearranged
to form each other.
• The strings "ate", "eat", and "tea" are anagrams as they can be
rearranged to form each other.
Example 2:
Input: strs = [""]
Output: [[""]]
Example 3:
Input: strs = ["a"]
Output: [["a"]]
Constraints:
• 1 <= strs.length <= 10^4
• 0 <= strs[i].length <= 100
• strs[i] consists of lowercase English letters.
"""
from collections import defaultdict
class Solution:
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
if not strs:
return strs
res = defaultdict(list)
for s in strs:
count = [0] * 26
for c in s:
count[ord(c) - ord("a")] += 1
res[tuple(count)].append(s)
return res.values()