Pulled live from my LeetCode profile β updates automatically every time this page loads. No manual edits, no fake numbers.
A structured daily grind journal β not a solution dump.
Every notebook follows a consistent format so each session actually teaches a pattern, not just a solution.
π Problem Statement
π‘ Intuition & Thought Process
π’ Brute Force
π Optimized
π Complexity Breakdown
Written in plain readable Python β Kaggle notebook style. Zero over-engineering.
| # | Notebook |
|---|---|
| 09 | Leetcode_09.ipynb |
| 50 | Leetcode_50.ipynb |
| 231 | Leetcode_231.ipynb |
| 326 | Leetcode_326.ipynb |
| 342 | Leetcode_342.ipynb |
| 509 | Leetcode_509.ipynb |
| 1137 | LeetCode_1137.ipynb |
| 1281 | Leetcode_1281.ipynb |
| 1431 | Leetcode_1431.ipynb |
| 2520 | Leetcode_2520.ipynb |
| - | Recursion_Practice.ipynb |
| - | Time_&_Space_Complexity.ipynb |
| # | Topic | Core Patterns | Status |
|---|---|---|---|
| 01 | Arrays & Hashing | HashMap, frequency count, prefix sum | β |
| 02 | Two Pointers | Shrink window, fast-slow, 3Sum | β |
| 03 | Sliding Window | Fixed & variable window | β |
| 04 | Stack / Monotonic | LIFO, next greater/smaller | β |
| 05 | Binary Search | Halving, rotated arrays | β |
| 06 | Linked Lists | Floyd's cycle, reversal, merge | β |
| 07 | Trees | DFS, BFS, recursion, LCA | β |
| 08 | Graphs | Union-Find, BFS/DFS traversal | β |
| 09 | Dynamic Programming | Memoization, tabulation | π |
| β | Backtracking | Permutations, subsets | π |
| β | Heaps & Priority Queue | Top-K, merge K sorted | π |
| β | Tries | Prefix tree, word search | π |
β Complete Β Β·Β π In Progress Β Β·Β π Upcoming
π Two Pointers β O(n) time Β· O(1) space
left, right = 0, len(arr) - 1
while left < right:
s = arr[left] + arr[right]
if s == target: return [left, right]
elif s < target: left += 1
else: right -= 1When to use: sorted array, pair sum, palindrome check, 3Sum, container with most water.
πͺ Sliding Window β O(n) time Β· O(k) space
left, best = 0, 0
window = {}
for right, ch in enumerate(s):
window[ch] = window.get(ch, 0) + 1
while len(window) > k: # shrink condition
window[s[left]] -= 1
if window[s[left]] == 0:
del window[s[left]]
left += 1
best = max(best, right - left + 1)
return bestWhen to use: max/min subarray, longest substring with constraint, contains duplicate in window.
π Monotonic Stack β O(n) time Β· O(n) space
stack, result = [], [-1] * len(arr)
for i, num in enumerate(arr):
while stack and arr[stack[-1]] < num:
result[stack.pop()] = num
stack.append(i)
return resultWhen to use: next greater element, daily temperatures, histogram max area, bracket matching.
π Binary Search β O(log n) time Β· O(1) space
lo, hi = 0, len(arr) - 1
while lo <= hi:
mid = lo + (hi - lo) // 2
if arr[mid] == target: return mid
elif arr[mid] < target: lo = mid + 1
else: hi = mid - 1
return -1When to use: sorted array, rotated sorted array, search on answer (min/max valid value).
π² DFS on Tree β O(n) time Β· O(h) space
def dfs(node):
if not node:
return 0
left = dfs(node.left)
right = dfs(node.right)
return 1 + max(left, right) # max depth exampleWhen to use: height/depth, path sum, LCA, subtree problems, serialization.
π BFS Level-Order β O(n) time Β· O(n) space
from collections import deque
q, result = deque([root]), []
while q:
level = []
for _ in range(len(q)):
node = q.popleft()
level.append(node.val)
if node.left: q.append(node.left)
if node.right: q.append(node.right)
result.append(level)
return resultWhen to use: shortest path, level-by-level traversal, multi-source BFS, word ladder.
π Union-Find (DSU) β O(Ξ±Β·n) β O(1) per op
parent = list(range(n))
rank = [0] * n
def find(x):
if parent[x] != x:
parent[x] = find(parent[x]) # path compression
return parent[x]
def union(x, y):
px, py = find(x), find(y)
if px == py: return False
if rank[px] < rank[py]: px, py = py, px
parent[py] = px
if rank[px] == rank[py]: rank[px] += 1
return TrueWhen to use: number of islands, redundant connection, accounts merge, connected components.
π° Dynamic Programming (bottom-up)
# Climbing stairs template
dp = [0] * (n + 1)
dp[1] = 1
dp[2] = 2
for i in range(3, n + 1):
dp[i] = dp[i-1] + dp[i-2]
return dp[n]
# 0/1 Knapsack template
dp = [[0] * (W + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
for w in range(W + 1):
dp[i][w] = dp[i-1][w]
if weights[i-1] <= w:
dp[i][w] = max(dp[i][w],
dp[i-1][w - weights[i-1]] + values[i-1])
return dp[n][W]When to use: overlapping subproblems, optimal substructure, count ways, min/max cost.
| Algorithm | Time | Space | Notes |
|---|---|---|---|
| Two Pointers | O(n) | O(1) | Requires sorted input |
| Sliding Window | O(n) | O(k) | k = window size |
| Binary Search | O(log n) | O(1) | Sorted / monotonic |
| BFS / DFS | O(V + E) | O(V) | Graph & tree traversal |
| Merge Sort | O(n log n) | O(n) | Stable, divide & conquer |
| Quick Sort | O(n log n) avg | O(log n) | In-place, unstable |
| Heap Push/Pop | O(log n) | O(n) | Priority queue ops |
| Union-Find | O(Ξ±Β·n) | O(n) | Near-constant per op |
| Dijkstra | O((V+E) log V) | O(V) | Non-negative weights |
| Topological Sort | O(V + E) | O(V) | DAG only |
# 1. Clone
git clone https://github.com/Kushagra524/LeetCode-DSA.git
cd LeetCode-DSA
# 2. Install Jupyter
pip install notebook
# 3. Open any notebook
jupyter notebook Leetcode_09.ipynbOr open directly in VS Code with the Jupyter extension β zero extra setup.
| Platform | Link |
|---|---|
| GitHub | github.com/Kushagra524 |
| Kaggle | kaggle.com/kushagrasrivastava21 |
| linkedin.com/in/kushagra-srivastava-19a170332 | |
| LeetCode | leetcode.com/u/kushagra_20 |
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β "First, solve the problem. Then, write the code." β
β β John Johnson β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Found it useful? Drop a β β it keeps the grind going.