This repository is for my personal LeetCode practice using mainly C++.
My initial target is to solve one or two problems per day. If I miss any problems during the weekdays, I will catch up on them over the weekend.(to be continued...)
- 📅 Phase 1: 2025-06-09 - 2025-06-29 one problem per day
- 📅 Phase 2: 2025-06-30 - 2025-08-24 ten problems(min) per week
- 📅 Phase 3: 2025-08-25 - 2025-12-07 seven problems(min) per week
- 📅 Phase 4: 2025-12-08 - now freestyle
- ✅ Total Problems Solved: 230/230
- 📈 Difficulty Breakdown: Easy(74) / Medium(135) / Hard(21) / Total(230)
- 🧠 Topics Covered: Linked List, Array, Dynamic Programming, Stack, etc.
➡️➡️➡️📚 Table of Contents⬅️⬅️⬅️
- leetcode-practice-in-cpp
- 🚀 LeetCode Training Progress
- 📋 Problem Overview
- 🏆 Contest Reviews
- 📚 Shared Solutions
- 🗂️ Problem Categories
- 📊 Array (Total: 5 problems)
- 🌀 Backtracking (Total: 12 problems)
- 🌲 Binary Search Tree (Total: 4 problems)
- 🔧 Bit Manipulation (Total: 14 problems)
- 🏗️ Design (Total: 2 problems)
- ⚡ Divide & Conquer (Total: 5 problems)
- 🎯 DP Grid / Matrix (Total: 5 problems)
- 🎯 DP Knapsack / Subset (Total: 5 problems)
- 🎯 DP Linear / Sequence (Total: 10 problems)
- 🎯 DP Math (Total: 6 problems)
- 🎯 DP String / Edit (Total: 5 problems)
- 🌐 Flood Fill / Connected Components (Total: 6 problems)
- 🕸️ Graph & Topological Sort (Total: 4 problems)
- 🧭 Greedy (Total: 19 problems)
- 🧩 Hash Map (Total: 11 problems)
- 🏔️ Heap / QuickSelect / Bucket (Total: 5 problems)
- 🔗 Linked List (Total: 9 problems)
- 📐 Math (Total: 15 problems)
- 📐 Math (Total: 3 problems)
- ➕ Prefix Sum (Total: 6 problems)
- 🔍 Search (Total: 14 problems)
- 🛣️ Shortest Path (Total: 2 problems)
- 🧮 Simulation (Total: 10 problems)
- 🌊 Sliding Window (Total: 3 problems)
- 🧱 Stack & Queue (Total: 11 problems)
- 🔤 String Processing (Total: 5 problems)
- 💡 Tree DP / Path Sum (Total: 4 problems)
- 🌳 Tree Traversal (Total: 12 problems)
- 🪝 Two Pointers (Total: 17 problems)
Each problem is placed in its own folder, which contains:
- A
.hppheader file for declarations - A
test.cppfile for testing all versions*(note: for new problems recorded from LeetCode, test.cpp may not yet exist; the original 200+ problems do have simple tests)* - Multiple
.cppfiles, each representing a different version of the solutioncontest.cpp: The original code written during the contest or simulated contestbrute_force.cpp: A straightforward or initial solution outside the contest contextoptimized.cpp: Improved or optimized solutionrefined.cpp: A further cleaned-up or more elegant version created during later review- May have the same complexity as
brute_force.cpporoptimized.cpp, but with better readability or slightly better runtime
- May have the same complexity as
- A
simple_test.hppandsimple_test.cpppair that provide common testing utilities used bytest.cppand solution files
To compile, just compile any solution .cpp together with test.cpp and simple_test.cpp.
Example: c++ -Wall -Wextra -Werror brute_force.cpp test.cpp ../../simple_test.cpp -o test && ./test
📌 If a problem folder only contains a brute_force version, that means it's either already the best I could come up with at the time — possibly even achieving 100% runtime — or it's a reasonable enough solution for now. I’ll revisit it if I come up with a better idea or gain a deeper understanding of the problem.
You can find all contest summaries and review notes in the contest_review.md file.
You can find all shared solution links and records in the shared.md file.
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0485 | Max Consecutive Ones | Easy | Runtime(100%) | consecutive count |
| 0645 | Set Mismatch | Easy | Runtime(100%) | Find duplicate & missing → hash / counting |
| 1365 | How Many Numbers Are Smaller Than The Current Number | Easy | Runtime(100%) | Count smaller |
| 1470 | Shuffle The Array | Easy | Runtime(100%) | Array reorder |
| 1929 | Concatenation Of Array | Easy | Runtime(100%) | Simple array manipulation |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0017 | Letter Combinations Of A Phone Number | Medium | Runtime(100%) | Classic digit-to-letter mapping → DFS/backtracking |
| 0022 | Generate Parentheses | Medium | Runtime(100%) | Backtracking with pruning → track left/right counts, reserve string capacity |
| 0037 | Sudoku Solver | Hard | Runtime(~94%) | Backtracking with pruning: Brute-force uses unordered_set; Optimized uses bitmask (int row[9], col[9], block[9]) + __builtin_ctz to pick candidates efficiently |
| 0039 | Combination Sum | Medium | Runtime(sometimes 100%) | Reuse numbers → sort + prune if > target, prevent duplicates via start |
| 0040 | Combination Sum II | Medium | Runtime(100%) | Use each number once → sort + prune + skip duplicates (i > start) |
| 0046 | Permutation | Medium | Runtime(100%) | Generate all permutations, used[] + path (fast) vs swap (less memory) |
| 0047 | Permutation II | Medium | Runtime(~75%), classic solution | Same as 46 but with duplicates → sort + skip !used[i-1] to prune |
| 0051 | N Queens | Hard | Runtime(100%) | Place queens row-by-row, prune with colUsed, diag1Used, diag2Used for O(1) validity check |
| 0077 | Combinations | Medium | Runtime(~90%) | Generate all k-combinations from 1..n → backtracking, use path and i+1 for next start |
| 0078 | Subsets | Medium | Runtime(100%) | Generate all subsets → Backtracking (DFS) or Bit Manipulation, use path and recursion for DFS |
| 0079 | Word Search | Medium | Runtime(98%) | DFS + backtracking on 2D grid, prune by length & char frequency, in-place visited mark |
| 0131 | Palindrome Partitioning | Medium | Runtime(~94%) improve later | Backtracking + DP precomputation for O(1) palindrome check |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0098 | Validate Binary Search Tree | Medium | Runtime(100%) | In-order traversal OR Recursive bounds check |
| 0108 | Convert Sorted Array To Binary Search Tree | Easy | sometimes Runtime(100%) | Divide & Conquer + Recursion |
| 0230 | Kth Smallest Element In A BST | Medium | Runtime(100%) | In-order traversal + pruning |
| 0235 | Lowest Common Ancestor Of A Binary Search Tree | Medium | Runtime(~88%) classic solution | Top-down search using BST property |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0136 | Single Number | Easy | Runtime(100%) | XOR all numbers → duplicates cancel out, leaving unique |
| 0137 | Single Number II | Medium | Runtime(100%) | Bit counting mod 3 / find unique appearing once when others appear three times |
| 0190 | Reverse Bits | Easy | Runtime(100%) | Shift & add each bit / reverse 32-bit integer |
| 0191 | Number Of 1 Bits | Easy | Runtime(100%) | Brian Kernighan’s algorithm / count set bits |
| 0231 | Power Of Two | Easy | Runtime(100%) | n & (n - 1) == 0 trick / check single set bit |
| 0260 | Single Number III | Medium | Runtime(100%) | XOR all numbers → partition by rightmost differing bit → isolate two unique numbers |
| 0268 | Missing Number | Easy | Runtime(100%) | XOR index and value → missing number remains |
| 0318 | Maximum Product Of Word Lengths | Medium | Runtime(40-50%) | Bitmask each word / compare non-overlapping masks for max length product |
| 0338 | Counting Bits | Easy | Runtime(100%) | DP + bitwise pattern / even → same as i>>1, odd → +1 |
| 0342 | Power Of Four | Easy | Runtime(100%) | Check power of two + odd bit position → n & 0x55555555 |
| 0371 | Sum Of Two Integers | Medium | Runtime(100%) | XOR for sum without carry & (a & b) << 1 carry |
| 0461 | Hamming Distance | Easy | Runtime(100%) | XOR to find differing bits + Brian Kernighan’s algorithm to count 1s |
| 0476 | Number Complement | Easy | Runtime(100%) | Build bitmask of 1s to match bit-length → ~num & mask gives complement |
| 0693 | Binary Number With Alternating Bits | Easy | Runtime(100%) | Check alternating bit pattern using bitwise properties |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0297 | Serialize And Deserialize Binary Tree | Hard | Runtime(~30%) improve later | Preorder DFS + # null marker, istringstream token parsing |
| 0382 | Linked List Random Node | Medium | Runtime(100%) | Reservoir Sampling for uniform random selection |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0050 | Pow(x,n) | Medium | Runtime(100%) | Fast exponentiation, O(log n) optimization |
| 0105 | Construct Binary Tree From Preorder And Inorder Traversal | Medium | Runtime(100%) | Recursively split inorder, build subtrees |
| 0148 | Sort List | Medium | Runtime(60-70%) | Bottom-up merge sort, O(n log n) & O(1) space |
| 0241 | Different Ways To Add Parentheses | Medium | Runtime(100%) | Divide & Conquer with memoization |
| 0932 | Beautiful Array | Medium | Runtime(100%) | Divide & Conquer construction, odd/even separation |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0064 | Minimum Path Sum | Medium | Runtime(100%) | Grid DP → can optimize to O(n) space with rolling array(later) |
| 0221 | Maximal Square | Medium | Runtime(vary a lot) | 2D DP → dp[i][j] stores maximal square side ending at (i,j) → depends on top, left, top-left neighbors → can optimize to O(n) space |
| 0304 | Range Sum Query 2D Immutable | Medium | Runtime(vary a lot) | 2D prefix sum / summed-area table → O(1) query time |
| 0542 | 01 Matrix | Medium | Runtime(~90%) | 2-pass DP → compute min distance to nearest 0 (top-left to bottom-right, then reverse) |
| 3603 | Minimum Cost Path With Alternating Direction II | Medium | Runtime(~95%) improve later | Grid DP with custom movement rule / 🏁 Biweekly 160(Q2) |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0279 | Perfect Squares | Medium | Runtime(~86%) | Complete knapsack DP → dp[i] = min(dp[i], dp[i - j²] + 1) |
| 0322 | Coin Change | Medium | Runtime(~82%) | 1D DP (Unbounded Knapsack) → dp[j] = min(dp[j], dp[j - coin] + 1), handle impossible states with INT_MAX-1 |
| 0416 | Partition Equal Subset Sum | Medium | Runtime(~80%) | 0/1 Knapsack DP → `dp[j] |
| 0474 | Ones And Zeros | Medium | Runtime(~82%) | 2D 0/1 Knapsack → dp[i][j] max strings with i zeros & j ones; iterate backwards to avoid reuse |
| 0494 | Target Sum | Medium | Runtime(100%) | Transform to subset sum → count subsets summing to (target + sum(nums))/2, use 1D DP with backward iteration |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0053 | Maximum Subarray | Medium | Runtime(100%) | Kadane’s Algorithm → O(n) time, O(1) space |
| 0121 | Best Time To Buy And Sell Stock | Easy | Runtime(sometimes 100%) | Track prefix min & update max profit in one pass |
| 0123 | Best Time To Buy And Sell Stock III | Hard | Runtime(sometimes 100%) | Two approaches: left-right profit split (O(n) space) or 4-state DP (O(1) space) |
| 0188 | Best Time To Buy And Sell Stock IV | Hard | Runtime(~85%) | State DP → buy[i], sell[i] for k transactions; optimize from 2D DP to O(k) space |
| 0198 | House Robber | Medium | Runtime(100%) | Classic DP → dp[i] = max(dp[i-1], dp[i-2] + nums[i]) → O(1) space optimized |
| 0213 | House Robber II | Medium | Runtime(100%) | Circular variant of 0198 → run twice on [0,n-2] & [1,n-1], then max |
| 0300 | Longest Increasing Subsequence | Medium | Runtime(100%) | Patience Sorting + Binary Search → O(n log n) |
| 0309 | Best Time To Buy And Sell Stock With Cooldown | Medium | Runtime(100%) | State-machine DP → hold / cool / rest states; enforces 1-day cooldown |
| 0413 | Arithmetic Slices | Medium | Runtime(100%) | DP → dp[i] = dp[i-1] + 1 if valid, sum(dp) for answer |
| 0714 | Best Time To Buy And Sell Stock With Transaction Fee | Medium | Runtime(100%) | DP with two states → hold (keep) & empty; update daily max profit; subtract fee on sell |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0070 | Climbing Stairs | Easy | Runtime(100%) | Fibonacci variant with safe integer handling |
| 0091 | Decode Ways | Medium | Runtime(100%) | DP → dp[i] = ways to decode s[0..i-1]; careful handling of 0 and two-digit numbers (10..26) |
| 0118 | Pascals Triangle | Easy | Runtime(100%) | Generate triangle row by row → row[j] = prev_row[j-1] + prev_row[j], edge 1’s |
| 0264 | Ugly Number II | Medium | Runtime(100%) | DP + 3 pointers → generate sequence by merging ×2,×3,×5 |
| 0313 | Super Ugly Number | Medium | Runtime(~89%) | DP + k pointers → merge k prime-generated streams, avoid duplicates |
| 0509 | Fibonacci Number | Easy | Runtime(sometimes 100%) | Classic DP → optimized to rolling variables |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0010 | Regular Expression Matching | Hard | Runtime(~52%) classic solution | 2D DP → simulate regex with . and *, careful initialization and transitions |
| 0072 | Edit Distance | Medium | Runtime(>70%) | 2D DP → dp[i][j] = min ops to convert prefix of word1→word2; handles insert/delete/replace |
| 0139 | Word Break | Medium | Runtime(100%) | DP → dp[i] = whether s[0..i-1] can be segmented; check all words ending at i |
| 0583 | Delete Operation For Two Strings | Medium | Runtime(65~90%) | 2D DP → LCS length → min deletions = len1 + len2 - 2*LCS; can optimize to O(n) space with rolling array |
| 1143 | Longest Common Subsequence | Medium | Runtime(vary a lot) classic solution | Classic LCS → 2D DP; dp[i][j] = LCS of prefixes; can optimize to O(min(m,n)) space |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0130 | Surrounded Regions | Medium | Runtime(100%) | DFS with temporary marking + revert step |
| 0417 | Pacific Atlantic Water Flow | Medium | Runtime(sometimes 100%) | Reverse flood fill from oceans / DFS |
| 0547 | Number Of Provinces | Medium | Runtime(100%) | Connected components in adjacency matrix / DFS |
| 0695 | Max Area Of Island | Medium | Runtime(100%) | Classic flood fill / DFS variants |
| 0934 | Shortest Bridge | Medium | Runtime(vary a lot) | Hybrid DFS + BFS: mark one island, expand to find shortest bridge |
| 3619 | Count Islands With Total Value Divisible By K | Medium | Runtime(~90%) classic solution | Flood fill via DFS and BFS comparison / 🏁 Biweekly 161(Q2) |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0207 | Course Schedule | Medium | Runtime(79%-100%) | Cycle detection, DAG check |
| 0310 | Minimum Height Trees | Medium | Runtime(~60%) | Trim leaves iteratively, tree centers |
| 0332 | Reconstruct Itinerary | Hard | Runtime(vary a lot) | Eulerian path, DFS + backtracking, lexical order |
| 3620 | Network Recovery Pathways | Hard | Runtime(>90%) | DAG shortest path + topo sort + binary search / / 🏁 Biweekly 161(Q3) |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0011 | Container With Most Water | Medium | Runtime(sometimes 100%) | Two pointers with greedy: always move the shorter line |
| 0122 | Best Time To Buy And Sell Stock II | Medium | Runtime(100%) | Greedy → accumulate all positive price differences |
| 0135 | Candy | Hard | Runtime(100%) | Greedy + two-pass scan: take max(left[i], right[i]) |
| 0169 | Majority Element | Easy | Runtime(100%) | Boyer-Moore Voting: greedy cancellation of minority elements |
| 0179 | Largest Number | Medium | Runtime(~77%), classic solution | Greedy + custom sorting: sort by a + b > b + a |
| 0376 | Wiggle Subsequence | Medium | Runtime(100%) | Greedy → track up / down to count alternating differences |
| 0406 | Queue Reconstruction By Height | Medium | Runtime(~71%) improve later | Greedy + sort by descending height, insert each person at index k; segment tree can optimize to O(n log n) |
| 0435 | Non_Overlapping_Intervals | Medium | Runtime(~73%) classic solution | Greedy + sorting by end time: always keep the interval that ends earliest |
| 0452 | Minimum Number Of Arrows To Burst Ballons | Medium | Runtime(~32%) classic solution | Greedy + sorting by end time: shoot arrows at earliest possible end |
| 0455 | Assign Cookies | Easy | Runtime(sometimes 100%) | Greedy + two pointers after sorting: assign smallest possible cookie to each child |
| 0605 | Can Place Flowers | Easy | Runtime(100%) | Greedy: check left/right neighbors, plant if both empty, early stop if n == 0 |
| 0646 | Maximum Length Of Pair Chain | Medium | Runtime(80-90%) | Greedy: sort by pair end, always pick next pair with start > previous end |
| 0665 | Non Decreasing Array | Medium | Runtime(100%) | Greedy: allow at most one violation, fix locally by lowering nums[i] or raising nums[i+1] |
| 0763 | Partition Labels | Medium | Runtime(100%) | Greedy + last occurrence: expand partition until reaching farthest boundary |
| 0768 | Max Chunks To Make Sorted II | Hard | Runtime(100%) | Greedy + monotonic stack: track max of each chunk, merge when arr[i] < stack.top() |
| 0769 | Max Chunks To Make Sorted | Medium | Runtime(100%) | Greedy + prefix max: when cur_max == i, one chunk can be cut |
| 0870 | Advantage Shuffle | Medium | Runtime(~99%) | use largest to beat largest, otherwise sacrifice smallest |
| 3635 | Earlies Finish Time For Land And Water Rides II | Medium | Runtime(~83%), classic solution | Greedy on earliest finish time in both orders (land→water / water→land) / 🏁 Biweekly 162(Q3) |
| 3664 | Two-Letter Card Game | Medium | Runtime varies, classic solution | Count cards by categories and use greedy pairing with leftovers (both, left, right) / 🏁 Biweekly 164(Q2) |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0001 | Two Sum | Easy | Runtime(100%) | One-pass hash map / complement lookup |
| 0128 | Longest Consecutive Sequence | Medium | Runtime(vary a lot) | Hash set / sequence start detection / O(n) |
| 0149 | Max Points On A Line | Hard | Runtime(~92%) | Slope hash map / duplicates / vertical lines |
| 0202 | Happy Number | Easy | Runtime(100%) | Hash set / cycle detection |
| 0205 | Isomorphic Strings | Easy | Runtime(100%) | Two-way mapping / fixed array optimization |
| 0217 | Contains Duplicate | Easy | Runtime(~70%) | Hash set / O(n) scan |
| 0242 | Valid Anagram | Easy | Runtime(100%) | Frequency counting / O(1) space |
| 0387 | First Unique Character In A String | Easy | Runtime(~70%, can improve later) | Array or hash map / two-pass scan |
| 0409 | Longest Palindrome | Easy | Runtime(100%) | Frequency counting / even part + odd center |
| 0594 | Longest Harmonious Subsequence | Easy | Runtime(>80%) | Frequency hash map / check consecutive numbers |
| 0697 | Degree Of An Array | Easy | Runtime(vary a lot) | Count / first & last index / shortest subarray |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0023 | Merge K Sorted Lists | Hard | Runtime(sometimes 100%) | min-heap (priority queue) |
| 0215 | Kth Largest Element In An Array | Medium | Runtime(>90%) | heap vs quick select |
| 0218 | The Skyline Problem | Hard | Runtime(~100%) | sweep line + max-heap (priority queue) |
| 0347 | Top K Frequent Elements | Medium | Runtime(100%) | bucket sort vs quick select |
| 0451 | Sort Characters By Frequency | Medium | Runtime(sometimes 100%) | bucket sort |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0021 | Merge Two Sorted Lists | Easy | Runtime(100%) | Recursive vs Iterative |
| 0024 | Swap Nodes In Pairs | Medium | Runtime(100%) | Pairwise swapping / Dummy node |
| 0083 | Remove Duplicates From Sorted List | Easy | Runtime(100%) | Skip consecutive equals |
| 0086 | Partition List | Medium | Runtime(100%) | Dummy node / In-place insertion |
| 0138 | Copy List With Random Pointer | Medium | Runtime(>90%,sometimes 100%) | Hash Map / In-place / O(1) extra space optimized |
| 0206 | Reverse Linked List | Easy | Runtime(100%) | Tail-cutting / Recursive / Iterative |
| 0234 | Palindrome Linked List | Easy | Runtime(100%) | Slow/Fast pointers / Reverse second half / In-place comparison |
| 0237 | Delete Node In A Linked List | Medium | Runtime(Not 100%), good enough | Loop-copy / O(1) overwrite |
| 0328 | Odd Even Linked List | Medium | Runtime(100%) | Odd/Even chain splitting / O(1) space |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0089 | Gray Code | Medium | Runtime(100%) | Generate Gray codes using i ^ (i >> 1) formula |
| 0168 | Excel Sheet Column Title | Easy | Runtime(100%) | Base-26 conversion with A–Z, subtract 1 each step to handle 1-based system |
| 0172 | Factorial Trailing Zeroes | Medium | Runtime(100%) | Count factors of 5 in n!; trailing zeros = sum of n/5 + n/25 + n/125 + ... |
| 0204 | Count Primes | Medium | Runtime(~90%) | Use Sieve of Eratosthenes; mark multiples; accumulate counts primes |
| 0233 | Number Of Digit One | Hard | Runtime(100%) | Digit counting by high/cur/low parts per digit |
| 0326 | Power Of Three | Easy | Runtime(sometimes 100%) | Check if n is divisible by 3 repeatedly; return true if final n is 1 |
| 0343 | Integer Break | Medium | Runtime(100%) | Break n into as many 3s as possible; handle mod=1 by turning 3+1→2+2 |
| 0400 | Nth Digit | Medium | Runtime(100%) | Digit block skipping → locate number & digit |
| 0462 | Minimum Moves To Equal Array Elements II | Medium | Runtime(sometimes 100%) | Minimize total distance by moving all elements to the median |
| 0470 | Implement Rand10() Using Rand7() | Medium | Runtime(vary a lot) | Use rejection sampling: generate 1–49 via (rand7()-1)*7+rand7(), keep ≤40 and map to 1–10 |
| 0504 | Base 7 | Easy | Runtime(100%) | Convert integer to base 7; handle sign; build digits in reverse |
| 0650 | 2 Keys Keyboard | Medium | Runtime(100%) | Min steps = sum of prime factors of n |
| 1823 | Find The Winner Of The Circular Game | Medium | Runtime(100%) | Josephus problem — recurrence: dp = (dp + k) % i |
| 3618 | Split Array By Prime Indices | Medium | Runtime(>70%) classic solution | Number theory + sieve of Eratosthenes / 🏁 Biweekly 161(Q1) |
| 3648 | Minimum Sensors To Cover Grid | Medium | Runtime(100%) | Coverage square side = 2k+1; ceil-div in both dims / 🏁 Biweekly 163(Q1) |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0503 | Next Greater Element II | Medium | Runtime(sometimes 100%) | Monotonic stack / Circular array / Push indices only in first pass |
| 0739 | Daily Temperatures | Medium | Runtime(~100%) | Monotonic stack / Next greater element |
| 1475 | Final Prices With a Special Discount in a Shop | Easy | Runtime(100%) | Maintain a monotonic increasing stack; find the next element <= current to compute discount |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0238 | Product Of Array Except Self | Medium | Runtime(100%) | Prefix product (left) × suffix product (right) without division |
| 0303 | Range Sum Query Immutable | Easy | Runtime(100%) | Prefix sum with O(1) range query |
| 0528 | Random Pick With Weight | Medium | Runtime(vary a lot) | Prefix sum + binary search for weighted random selection |
| 0560 | Subarray Sum Equals K | Medium | Runtime(~50%) | Prefix sum + hash map to count matching prefix differences |
| 0724 | Find Pivot Index | Easy | Runtime(100%) | Compare left and right prefix sum |
| 1480 | Running Sum Of 1d Array | Easy | Runtime(100%) | Basic prefix sum building cumulatively |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0004 | Median Of Two Sorted Arrays | Hard | Runtime(100%) | Binary search on partition of shorter array → O(log(min(m,n))) |
| 0033 | Search In Rotated Sorted Array | Medium | Runtime(100%) | Binary search with rotation awareness → O(log n) |
| 0034 | Find First And Last Position Of Element In Sorted Array | Medium | Runtime(100%) | Two binary searches to find left and right boundaries → O(log n) |
| 0035 | Search Insert Position | Easy | Runtime(100%) | Lower Bound implementation → O(log n) |
| 0069 | Sqrt(x) | Easy | Runtime(100%) | Binary search for integer square root → O(log n) |
| 0074 | Search A 2D Matrix | Medium | Runtime(100%) | Treat matrix as 1D array + binary search → O(log(m·n)) |
| 0081 | Search In Rotated Sorted Array II | Medium | Runtime(100%) | Binary search with rotation + duplicates → O(n) worst case |
| 0153 | Find Minimum In Rotated Sorted Array | Medium | Runtime(100%) | Binary search for rotation pivot → O(log n) |
| 0154 | Find Minimum In Rotated Sorted Array II | Hard | Runtime(100%) | Binary Search with Duplicates |
| 0240 | Search A 2D Matrix II | Medium | Runtime(vary a lot), classic solution | Monotonic matrix search from top-right corner → O(m+n) |
| 0278 | First Bad Version | Easy | Runtime(~55%) classic solution | Find first true with minimal API calls / Lower Bound |
| 0540 | Single Element In A Sorted Array | Medium | Runtime(100%) | Binary search with pair index check → O(log n) |
| 0647 | Palindromic Substrings | Medium | Runtime(~70%) | Expand-around-center on all 2n−1 centers → O(n²) |
| 0704 | Binary Search | Easy | Runtime(100%) | Classic binary search on sorted array |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0126 | Word Ladder II | Hard | Runtime(~45%) | BFS to find shortest depth + backtracking to reconstruct all shortest paths |
| 3650 | Minimum Cost Path With Edge Reversals | Medium | Runtime(~95%) | Model each edge as two directed edges (original cost and 2× cost for reversal) and solve with Dijkstra / 🏁 Biweekly 163(Q3) |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0048 | Rotate Image | Medium | Runtime(100%) | Simulate 90° rotation by transpose + row reversal |
| 0054 | Spiral Matrix | Medium | Runtime(100%) | Simulate matrix traversal by shrinking boundaries |
| 0059 | Spiral Matrix II | Medium | Runtime(100%) | Simulate spiral filling using 4 dynamic boundaries |
| 0384 | Shuffle An Array | Medium | Runtime(vary a lot) | Fisher-Yates shuffle to generate uniform random permutation; store original array for reset |
| 0415 | Add Strings | Easy | Runtime(100%) | Simulate digit-by-digit addition / carry tracking |
| 0448 | Find All Numbers Disappeared In An Array | Easy | Runtime(vary a lot), classic solution | Mark visited indices in-place using negation |
| 0566 | Reshape The Matrix | Easy | Runtime(100%) | Flatten and remap elements in row-major order; check reshape validity |
| 0796 | Rotate String | Easy | Runtime(100%) | Simulate string rotation by manual character comparison |
| 3602 | Hexadecimal And Hexatrigesimal Conversion | Easy | Runtime(100%) | Simulate base conversion with custom digit set / 🏁 Biweekly 160(Q1) |
| 3633 | Earlies Finish Time For Land And Water Rides I | Easy | Runtime(20%), better solution in 3635 | Brute-force simulate both orders (land→water / water→land) / 🏁 Biweekly 162(Q1) |
| 3663 | Find The Least Frequent Digit | Easy | Runtime(100%) | Counting digits / 🏁 Biweekly 164(Q1) |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0076 | Minimum Window Substring | Hard | Runtime(100%) | Classic sliding window with char count & shrink |
| 0239 | Sliding Window Maximum | Hard | Runtime(~99%) | Monotonic deque & heap approaches |
| 3634 | Minimum Removals To Balance Array | Medium | Runtime(vary a lot), classic solution | Sort + sliding window (two pointers) / 🏁 Biweekly 162(Q2) |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0020 | Valid Parentheses | Easy | Runtime(100%) | Stack / Bracket matching |
| 0150 | Evaluate Reverse Polish Notation | Medium | Runtime(100%) | Stack / Evaluate postfix expression |
| 0155 | Min Stack | Medium | Runtime(~45% but classic, can improve later) | Two-stack approach / O(1) min |
| 0225 | Implement Stack Using Queues | Easy | Runtime(100%) | Single queue rotation / Push O(n), others O(1) |
| 0227 | Basic Calculator II | Medium | Runtime(sometimes 100%) | Operator precedence / O(n) scan |
| 0232 | Implement Queue Using Stacks | Easy | Runtime(100%) | Two-stack queue / Amortized O(1) ops |
| 0295 | Find Median From Data Stream | Hard | Runtime(varies a lot) | Two heaps / O(log n) insert, O(1) median |
| 0394 | Decode String | Medium | Runtime(100%) | Recursion & Stack / Nested string decode |
| 0636 | Exclusive Time Of Functions | Medium | Runtime(100%) | Stack / Function call simulation |
| 0946 | Validate Stack Sequences | Medium | Runtime(100%) | Simulate push/pop behavior with a real stack |
| 1441 | Build An Array With Stack Operations | Medium | Runtime(100%) | Stack simulation / Sequential push-pop control |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0006 | Zigzag Conversion | Medium | Runtime(100%) | Simulation + direction control + reserve optimization |
| 0008 | String To Interger Atoi | Medium | Runtime(100%) | Manual parse + overflow clamp + long long use |
| 0028 | Find The Index Of The First Occurrence In A String | Easy | Runtime(100%) | KMP algorithm + LPS array + O(m+n) |
| 0067 | Add Binary | Easy | Runtime(100%) | Reverse + carry handling + reserve optimization |
| 0151 | Reverse Words In A String | Medium | Runtime(100%) | Backward scan + substr + reserve optimization |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0113 | Path Sum II | Medium | Runtime(100%) | DFS + Backtracking |
| 0124 | Binary Tree Maximum Path Sum | Hard | Runtime(100%) | DFS + Tree DP |
| 0437 | Path Sum III | Medium | Runtime(100%) | DFS + Prefix Sum + HashMap |
| 0543 | Diameter Of Binary Tree | Easy | Runtime(100%) | DFS + Tree DP |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0094 | Binary Tree Inorder Traversal | Easy | Runtime(100%) | DFS recursion |
| 0101 | Symmetric Tree | Easy | Runtime(100%) | DFS recursion & BFS queue mirror check |
| 0102 | Binary Tree Level Order Traversal | Medium | Runtime(100%) | BFS using queue |
| 0103 | Binary Tree Zigzag Level Order Traversal | Medium | Runtime(100%) | BFS with alternating direction |
| 0104 | Maximum Depth Of Binary Tree | Easy | Runtime(100%) | DFS recursion & BFS level count |
| 0110 | Balanced Binary Tree | Easy | Runtime(100%) | DFS + pruning, early exit on unbalanced |
| 0144 | Binary Tree Preorder Traversal | Easy | Runtime(100%) | Iterative DFS using stack, Root→Left→Right |
| 0226 | Invert Binary Tree | Easy | Runtime(100%) | DFS recursion & BFS swap children |
| 0236 | Lowest Common Ancestor Of A Binary Tree | Medium | Runtime(~60%) classic solution | Post-order recursion (LCA logic) |
| 0257 | Binary Tree Paths | Easy | Runtime(100%) | DFS recursion, build path strings root→leaf |
| 0637 | Average Of Levels In Binary Tree | Easy | Runtime(100%) | BFS level-order sum & count |
| 1110 | Delete Nodes And Return Forest | Medium | Runtime(vary a lot) | DFS + post-order, handle forest of trees |
| # | Title | Difficulty | Solution Folder | Notes |
|---|---|---|---|---|
| 0003 | Longest Substring Without Repeating Characters | Medium | Runtime(100%) | Sliding window (brute-force, map, array) / O(n) optimized |
| 0005 | Longest Palindromic Substring | Medium | Runtime(~90%) | Expand Around Center / Two pointers / O(n²) |
| 0015 | 3Sum | Medium | Runtime(~53%), classic solution | Sort + two pointers / Skip duplicates / O(n²) |
| 0019 | Remove Nth Node From End Of List | Medium | Runtime(100%) | Two pointers with dummy head / Fixed gap (n+1) / One pass |
| 0075 | Sort Colors | Medium | Runtime(100%) | Dutch National Flag / Three pointers / In-place / O(n) |
| 0088 | Merge Sorted Array | Easy | Runtime(100%) | Two pointers from back / In-place merge / O(m+n) |
| 0142 | Linked List Cycle II | Medium | Runtime(80-90%) | Fast-slow pointer to find cycle start |
| 0160 | Intersection Of Two Linked Lists | Easy | Runtime(~80%), classic solution | Two-pointer with list switching |
| 0167 | Two Sum II Input Array Is Sorted | Medium | Runtime(100%) | Two-pointer / Sorted array |
| 0287 | Find The Duplicate Number | Medium | Runtime(~70%) classic solution | Floyd’s cycle (fast/slow) & Binary search |
| 0392 | Is Subsequence | Easy | Runtime(100%) | Two-pointer / String scan |
| 0524 | Longest Word In Dictionary Through Deleting | Medium | Runtime(100%) | Two-pointer subsequence check / Track longest + lexicographically smallest |
| 0633 | Sum Of Square Numbers | Medium | Runtime(100%) | Two pointers (0 ~ √c) / Check sum of squares |
| 0680 | Valid Palindrome II | Easy | Runtime(sometimes 100%) | Two-pointer with one deletion / Check substrings when mismatch |
| 0696 | Count Binary Substrings | Easy | Runtime(100%) | Track consecutive 0/1 groups / Single pass O(n) / Constant space |
| 0876 | Middle Of The Linked List | Easy | Runtime(100%) | Fast-slow pointer on Linked List |
| 3649 | Number Of Perfect Pairs | Medium | Runtime(vary a lot) | Sort + two pointers on absolute values / Count pairs satisfying y ≤ 2x / 🏁 Biweekly 163(Q2) |