A structured archive of my daily LeetCode grind — solving problems, mastering patterns, and building interview-ready DSA skills in C++.
- About
- LeetCode Stats
- Problem Categories
- Topics Solved
- Example Solutions
- DSA Patterns Guide
- Getting Started
- Goals & Roadmap
- Resources
- Connect With Me
"LeetCode is not about memorizing solutions — it's about recognizing patterns, building intuition, and training your problem-solving brain."
This repository is my personal archive of LeetCode solutions, written in C++, organized by topic and difficulty. Every solution here is:
- ✅ Accepted on LeetCode
- 💡 Pattern-focused — not just solving, but understanding why it works
- 📝 Commented — with logic explained inline
- 🔁 Revisited — some problems solved multiple ways for deeper understanding
Whether you're a beginner starting your DSA journey or an experienced coder prepping for interviews, this repo is a useful reference to learn from real, working solutions.
| Metric | Details |
|---|---|
| 🏷️ LeetCode Handle | @leetcode_break |
| 💻 Primary Language | C++ |
| 🎯 Current Focus | Arrays, Strings, Hash Maps, Two Pointers |
| 📈 Streak | Active & Growing |
| Category | Problems Solved | Difficulty Mix | Status |
|---|---|---|---|
| 🔢 Arrays | 17 | Easy + Medium | ✅ Active |
| 🔤 Strings | 11 | Easy + Medium | ✅ Active |
| 📚 Hash Table | 8 | Easy + Medium | ✅ Active |
| 🧮 Math | 15 | Easy + Medium | ✅ Active |
| 🔄 Two Pointers | 3 | Easy | ✅ Active |
| 🔍 Binary Search | 2 | Easy | ✅ Active |
| 📊 Prefix Sum | 3 | Easy + Medium | ✅ Active |
| 🌊 Sliding Window | 1 | Medium | ✅ Active |
| 🧩 Dynamic Programming | 2 | Easy + Medium | 🔄 Learning |
| 🎮 Game Theory | 3 | Easy + Medium | 🔄 Learning |
| 🔁 Recursion | 1 | Medium | 🔄 Learning |
| 🔀 Sorting | 5 | Easy | ✅ Active |
| 🔬 Backtracking | 1 | Medium | 🔄 Learning |
| 🌐 BFS | 1 | Medium | 🔄 Learning |
| 🌲 Trees | 0 | — | 🔜 Coming Soon |
| 🔗 Linked List | 0 | — | 🔜 Coming Soon |
| 🧠 DP (Advanced) | 0 | — | 📅 Planned |
| 🏗️ Graphs | 0 | — | 📅 Planned |
| # | Problem | Difficulty |
|---|---|---|
| 0009 | Palindrome Number | 🟢 Easy |
| 0012 | Integer to Roman | 🟡 Medium |
| 0050 | Pow(x, n) | 🟡 Medium |
| 0507 | Perfect Number | 🟢 Easy |
| 0877 | Stone Game | 🟡 Medium |
| 1025 | Divisor Game | 🟢 Easy |
| 1323 | Maximum 69 Number | 🟢 Easy |
| 1486 | XOR Operation in an Array | 🟢 Easy |
| 1688 | Count of Matches in Tournament | 🟢 Easy |
| 1716 | Calculate Money in LeetCode Bank | 🟢 Easy |
| 2769 | Find the Maximum Achievable Number | 🟢 Easy |
| 2894 | Divisible and Non-Divisible Sums Difference | 🟢 Easy |
| 2946 | Matrix Similarity After Cyclic Shifts | 🟢 Easy |
| 3227 | Vowels Game in a String | 🟡 Medium |
| 3289 | The Two Sneaky Numbers of Digitville | 🟢 Easy |
| # | Problem | Difficulty |
|---|---|---|
| 0001 | Two Sum | 🟢 Easy |
| 0027 | Remove Element | 🟢 Easy |
| 0350 | Intersection of Two Arrays II | 🟢 Easy |
| 0877 | Stone Game | 🟡 Medium |
| 0994 | Rotting Oranges | 🟡 Medium |
| 1582 | Special Positions in a Binary Matrix | 🟢 Easy |
| 1732 | Find the Highest Altitude | 🟢 Easy |
| 1886 | Determine Whether Matrix Can Be Obtained By Rotation | 🟢 Easy |
| 1980 | Find Unique Binary String | 🟡 Medium |
| 2798 | Number of Employees Who Met the Target | 🟢 Easy |
| 2824 | Count Pairs Whose Sum is Less Than Target | 🟢 Easy |
| 2906 | Construct Product Matrix | 🟡 Medium |
| 2946 | Matrix Similarity After Cyclic Shifts | 🟢 Easy |
| 2974 | Minimum Number Game | 🟢 Easy |
| 3289 | The Two Sneaky Numbers of Digitville | 🟢 Easy |
| 3467 | Transform Array by Parity | 🟢 Easy |
| 3546 | Equal Sum Grid Partition I | 🟡 Medium |
| # | Problem | Difficulty |
|---|---|---|
| 0003 | Longest Substring Without Repeating Characters | 🟡 Medium |
| 0012 | Integer to Roman | 🟡 Medium |
| 0205 | Isomorphic Strings | 🟢 Easy |
| 0242 | Valid Anagram | 🟢 Easy |
| 1689 | Partitioning Into Minimum Number of Deci-Binary Numbers | 🟡 Medium |
| 1758 | Minimum Changes to Make Alternating Binary String | 🟢 Easy |
| 1784 | Check if Binary String Has at Most One Segment of Ones | 🟢 Easy |
| 1980 | Find Unique Binary String | 🟡 Medium |
| 2839 | Check if Strings Can Be Made Equal With Operations I | 🟢 Easy |
| 3110 | Score of a String | 🟢 Easy |
| 3227 | Vowels Game in a String | 🟡 Medium |
| # | Problem | Difficulty |
|---|---|---|
| 0001 | Two Sum | 🟢 Easy |
| 0003 | Longest Substring Without Repeating Characters | 🟡 Medium |
| 0205 | Isomorphic Strings | 🟢 Easy |
| 0242 | Valid Anagram | 🟢 Easy |
| 0350 | Intersection of Two Arrays II | 🟢 Easy |
| 1980 | Find Unique Binary String | 🟡 Medium |
| 3289 | The Two Sneaky Numbers of Digitville | 🟢 Easy |
| # | Problem | Difficulty |
|---|---|---|
| 0877 | Stone Game | 🟡 Medium |
| 1025 | Divisor Game | 🟢 Easy |
| # | Problem | Difficulty |
|---|---|---|
| 0003 | Longest Substring Without Repeating Characters | 🟡 Medium |
| # | Problem | Difficulty |
|---|---|---|
| 0027 | Remove Element | 🟢 Easy |
| 0350 | Intersection of Two Arrays II | 🟢 Easy |
| 2824 | Count Pairs Whose Sum is Less Than Target | 🟢 Easy |
| # | Problem | Difficulty |
|---|---|---|
| 0994 | Rotting Oranges | 🟡 Medium |
| # | Problem | Difficulty |
|---|---|---|
| 1732 | Find the Highest Altitude | 🟢 Easy |
| 2906 | Construct Product Matrix | 🟡 Medium |
| 3546 | Equal Sum Grid Partition I | 🟡 Medium |
Problem: Find two indices such that nums[i] + nums[j] = target
Intuition: Instead of checking every pair (O(n²)), use a hash map to store complements. For each number, check if its complement already exists — O(n) time.
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
unordered_map<int, int> mp; // stores: {value → index}
for (int i = 0; i < nums.size(); i++) {
int diff = target - nums[i]; // what we need
if (mp.count(diff)) // already seen it?
return {mp[diff], i}; // return both indices
mp[nums[i]] = i; // store current number
}
return {};
}
};
// Time: O(n) | Space: O(n)Problem: Find the length of the longest substring without duplicate characters.
Intuition: Use two pointers (left, right) as a sliding window. Expand right, and when a duplicate is found, shrink from the left.
class Solution {
public:
int lengthOfLongestSubstring(string s) {
unordered_map<char, int> mp; // char → last seen index
int left = 0, maxLen = 0;
for (int right = 0; right < s.size(); right++) {
if (mp.count(s[right]) && mp[s[right]] >= left)
left = mp[s[right]] + 1; // shrink window
mp[s[right]] = right; // update position
maxLen = max(maxLen, right - left + 1);
}
return maxLen;
}
};
// Time: O(n) | Space: O(min(n, m)) where m = charset sizeProblem: Find how many minutes until all oranges rot. Return -1 if impossible.
Intuition: Use multi-source BFS starting from all rotten oranges simultaneously. Each BFS level = 1 minute.
class Solution {
public:
int orangesRotting(vector<vector<int>>& grid) {
queue<pair<int,int>> q;
int fresh = 0, minutes = 0;
int m = grid.size(), n = grid[0].size();
// Add all rotten oranges to queue
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++) {
if (grid[i][j] == 2) q.push({i, j});
if (grid[i][j] == 1) fresh++;
}
int dirs[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};
while (!q.empty() && fresh > 0) {
int sz = q.size();
while (sz--) {
auto [r, c] = q.front(); q.pop();
for (auto& d : dirs) {
int nr = r + d[0], nc = c + d[1];
if (nr >= 0 && nr < m && nc >= 0 && nc < n && grid[nr][nc] == 1) {
grid[nr][nc] = 2;
fresh--;
q.push({nr, nc});
}
}
}
minutes++;
}
return fresh == 0 ? minutes : -1;
}
};
// Time: O(m×n) | Space: O(m×n)Understanding patterns is the key to cracking any LeetCode problem. Here are the most important ones:
Use when: subarray/substring problems with a constraint
→ Fixed window: slide without resizing
→ Variable window: expand right, shrink left when violated
Examples: Longest Substring, Max Sum Subarray
Use when: sorted array, pair/triplet sum, palindrome check
→ Opposite ends: left=0, right=n-1, move toward center
→ Same direction: fast/slow pointers
Examples: Two Sum II, Remove Duplicates, Container With Most Water
Use when: frequency count, complement lookup, duplicate detection
→ Store: value → index, value → count
→ Check: O(1) lookup instead of O(n) search
Examples: Two Sum, Valid Anagram, Group Anagrams
Use when: range sum queries, subarray sum problems
→ Precompute: prefix[i] = sum of first i elements
→ Query: sum(l,r) = prefix[r] - prefix[l-1]
Examples: Find Highest Altitude, Subarray Sum Equals K
Use when: shortest path, level-by-level traversal, grid problems
→ Use a queue, process level by level
→ Multi-source BFS: add all sources to queue at once
Examples: Rotting Oranges, Word Ladder, 01 Matrix
Use when: optimal substructure + overlapping subproblems
→ Top-down: recursion + memoization
→ Bottom-up: tabulation (iterative)
Examples: Climbing Stairs, Coin Change, Longest Common Subsequence
Want to explore or run these solutions locally?
git clone https://github.com/Anjali56-creator/Leetcode-submissions.git
cd Leetcode-submissions# Compile
g++ -o solution 0001-two-sum/solution.cpp
# Run
./solution- IDE: VS Code with C/C++ extension
- Compiler: g++ (GCC 11+)
- Online Judge: LeetCode for testing
Phase 1 — Foundation (Current) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✅ Arrays & Strings
✅ Hash Maps & Frequency Counting
✅ Math & Simulation
✅ Two Pointers & Binary Search basics
✅ Prefix Sum
Phase 2 — Core Patterns ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🔄 Sliding Window (advanced problems)
🔄 Recursion & Backtracking
🔄 Dynamic Programming (1D → 2D)
🔄 Stack & Queue
📅 Linked List (reversal, fast-slow pointer)
Phase 3 — Advanced DSA ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📅 Trees (DFS, BFS, LCA)
📅 Graphs (BFS, DFS, Dijkstra, Union-Find)
📅 Heaps & Priority Queue
📅 Tries
📅 Segment Trees
Phase 4 — Interview Ready ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📅 150+ problems solved across all categories
📅 Timed mock contests
📅 Top interview questions (Meta, Google, Amazon sets)
📅 System Design basics
- 50 problems solved
- 100 problems solved
- 200 problems solved
- Complete Blind 75
- Complete NeetCode 150
- Achieve LeetCode Rating 1500+
- Introduction to Algorithms (CLRS) — Cormen et al.
- Competitive Programming 3 — Steven & Felix Halim
- Cracking the Coding Interview — Gayle Laakmann McDowell
| Platform | Purpose |
|---|---|
| LeetCode | Primary problem solving |
| NeetCode.io | Pattern-based roadmap |
| Striver's A2Z Sheet | Structured DSA curriculum |
| CP-Algorithms | Algorithm reference |
| Visualgo | Algorithm visualization |
- NeetCode — Pattern explanations with clean C++ code
- take U forward (Striver) — In-depth DSA in C++
- Abdul Bari — Algorithm theory and intuition
DSA Enthusiast | C++ Developer | Problem Solver in Progress
"Every problem solved is a new pattern learned. Every pattern learned is a step closer to mastery." 🚀
This repository is open-source under the MIT License.
Feel free to reference solutions, but challenge yourself to solve them independently first — that's where the real growth happens! 💪
| Problem Name | Difficulty |
|---|---|
| 0003-longest-substring-without-repeating-characters | Medium |
| 0013-roman-to-integer | Easy |
| 0290-word-pattern | Easy |
| 0344-reverse-string | Easy |
| 0657-robot-return-to-origin | Easy |
| 0796-rotate-string | Easy |
| 2011-final-value-of-variable-after-performing-operations | Easy |
| 2515-shortest-distance-to-target-string-in-a-circular-array | Easy |
| 2833-furthest-point-from-origin | Easy |
| 2942-find-words-containing-character | Easy |
| Problem Name | Difficulty |
|---|---|
| 0657-robot-return-to-origin | Easy |
| 2011-final-value-of-variable-after-performing-operations | Easy |
| 2181-merge-nodes-in-between-zeros | Medium |
| 2553-separate-the-digits-in-an-array | Easy |
| 3653-xor-after-range-multiplication-queries-i | Medium |
| 3701-compute-alternating-sum | Easy |
| Problem Name | Difficulty |
|---|---|
| 0003-longest-substring-without-repeating-characters | Medium |
| 0013-roman-to-integer | Easy |
| 0290-word-pattern | Easy |
| 2540-minimum-common-value | Easy |
| 2615-sum-of-distances | Medium |
| 2657-find-the-prefix-common-array-of-two-arrays | Medium |
| 2784-check-if-array-is-good | Easy |
| 3668-restore-finishing-order | Easy |
| Problem Name | Difficulty |
|---|---|
| 0003-longest-substring-without-repeating-characters | Medium |
| Problem Name | Difficulty |
|---|---|
| 3653-xor-after-range-multiplication-queries-i | Medium |
| Problem Name | Difficulty |
|---|---|
| 0015-3sum | Medium |
| 0019-remove-nth-node-from-end-of-list | Medium |
| 0061-rotate-list | Medium |
| 0189-rotate-array | Medium |
| 0234-palindrome-linked-list | Easy |
| 0344-reverse-string | Easy |
| 0876-middle-of-the-linked-list | Easy |
| 1855-maximum-distance-between-a-pair-of-values | Medium |
| 1861-rotating-the-box | Medium |
| 2540-minimum-common-value | Easy |
| Problem Name | Difficulty |
|---|---|
| 0015-3sum | Medium |
| 1665-minimum-initial-energy-to-finish-tasks | Hard |
| 2037-minimum-number-of-moves-to-seat-everyone | Easy |
| 2089-find-target-indices-after-sorting-array | Easy |
| 2463-minimum-total-distance-traveled | Hard |
| 2784-check-if-array-is-good | Easy |
| Problem Name | Difficulty |
|---|---|
| 0009-palindrome-number | Easy |
| 0013-roman-to-integer | Easy |
| 0029-divide-two-integers | Medium |
| 0048-rotate-image | Medium |
| 0189-rotate-array | Medium |
| 0396-rotate-function | Medium |
| 0441-arranging-coins | Easy |
| 0788-rotated-digits | Medium |
| 1863-sum-of-all-subset-xor-totals | Easy |
| 2652-sum-multiples | Easy |
| 2807-insert-greatest-common-divisors-in-linked-list | Medium |
| 3516-find-closest-person | Easy |
| 3783-mirror-distance-of-an-integer | Easy |
| Problem Name | Difficulty |
|---|---|
| 0153-find-minimum-in-rotated-sorted-array | Medium |
| 0154-find-minimum-in-rotated-sorted-array-ii | Hard |
| 0441-arranging-coins | Easy |
| 1855-maximum-distance-between-a-pair-of-values | Medium |
| 2089-find-target-indices-after-sorting-array | Easy |
| 2540-minimum-common-value | Easy |
| Problem Name | Difficulty |
|---|---|
| 0396-rotate-function | Medium |
| 0788-rotated-digits | Medium |
| 2463-minimum-total-distance-traveled | Hard |
| 2770-maximum-number-of-jumps-to-reach-the-last-index | Medium |
| 3660-jump-game-ix | Medium |
| Problem Name | Difficulty |
|---|---|
| 0029-divide-two-integers | Medium |
| 1863-sum-of-all-subset-xor-totals | Easy |
| 2657-find-the-prefix-common-array-of-two-arrays | Medium |
| Problem Name | Difficulty |
|---|---|
| 1665-minimum-initial-energy-to-finish-tasks | Hard |
| 2037-minimum-number-of-moves-to-seat-everyone | Easy |
| 2078-two-furthest-houses-with-different-colors | Easy |
| Problem Name | Difficulty |
|---|---|
| 0547-number-of-provinces | Medium |
| Problem Name | Difficulty |
|---|---|
| 0547-number-of-provinces | Medium |
| Problem Name | Difficulty |
|---|---|
| 0547-number-of-provinces | Medium |
| Problem Name | Difficulty |
|---|---|
| 0547-number-of-provinces | Medium |
| Problem Name | Difficulty |
|---|---|
| 2615-sum-of-distances | Medium |
| Problem Name | Difficulty |
|---|---|
| 2833-furthest-point-from-origin | Easy |
| Problem Name | Difficulty |
|---|---|
| 2037-minimum-number-of-moves-to-seat-everyone | Easy |
| Problem Name | Difficulty |
|---|---|
| 0019-remove-nth-node-from-end-of-list | Medium |
| 0061-rotate-list | Medium |
| 0206-reverse-linked-list | Easy |
| 0234-palindrome-linked-list | Easy |
| 0876-middle-of-the-linked-list | Easy |
| 2181-merge-nodes-in-between-zeros | Medium |
| 2807-insert-greatest-common-divisors-in-linked-list | Medium |
| Problem Name | Difficulty |
|---|---|
| 0206-reverse-linked-list | Easy |
| 0234-palindrome-linked-list | Easy |
| Problem Name | Difficulty |
|---|---|
| 0796-rotate-string | Easy |
| Problem Name | Difficulty |
|---|---|
| 0048-rotate-image | Medium |
| 1861-rotating-the-box | Medium |
| Problem Name | Difficulty |
|---|---|
| 0234-palindrome-linked-list | Easy |
| Problem Name | Difficulty |
|---|---|
| 2807-insert-greatest-common-divisors-in-linked-list | Medium |
| Problem Name | Difficulty |
|---|---|
| 1863-sum-of-all-subset-xor-totals | Easy |
| Problem Name | Difficulty |
|---|---|
| 1863-sum-of-all-subset-xor-totals | Easy |
| Problem Name | Difficulty |
|---|---|
| 1863-sum-of-all-subset-xor-totals | Easy |