Skip to content

Anjali56-creator/Leetcode-submissions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

665 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


🧠 LeetCode Submissions

A structured archive of my daily LeetCode grind — solving problems, mastering patterns, and building interview-ready DSA skills in C++.


C++ LeetCode Problems Solved DSA


GitHub Last Commit Repo Size Top Language Stars Forks


📋 Table of Contents


📖 About

"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.


📊 My LeetCode Stats

LeetCode Stats Card



Metric Details
🏷️ LeetCode Handle @leetcode_break
💻 Primary Language C++
🎯 Current Focus Arrays, Strings, Hash Maps, Two Pointers
📈 Streak Active & Growing

📈 Repo Stats


🚀 Problem Categories

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

📂 Topics Solved

🧮 Math

# 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

🔢 Array

# 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

🔤 String

# 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

📚 Hash Table

# 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

🧠 Dynamic Programming

# Problem Difficulty
0877 Stone Game 🟡 Medium
1025 Divisor Game 🟢 Easy

🌊 Sliding Window

# Problem Difficulty
0003 Longest Substring Without Repeating Characters 🟡 Medium

🔄 Two Pointers

# Problem Difficulty
0027 Remove Element 🟢 Easy
0350 Intersection of Two Arrays II 🟢 Easy
2824 Count Pairs Whose Sum is Less Than Target 🟢 Easy

🌐 Breadth-First Search

# Problem Difficulty
0994 Rotting Oranges 🟡 Medium

📊 Prefix Sum

# Problem Difficulty
1732 Find the Highest Altitude 🟢 Easy
2906 Construct Product Matrix 🟡 Medium
3546 Equal Sum Grid Partition I 🟡 Medium

🔥 Example Solutions with Explanation

✅ Two Sum — Hash Map Approach

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)

✅ Longest Substring Without Repeating Characters — Sliding Window

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 size

✅ Rotting Oranges — BFS (Multi-source)

Problem: 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)

🗺️ DSA Patterns Guide

Understanding patterns is the key to cracking any LeetCode problem. Here are the most important ones:

🌊 Sliding Window

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

🔄 Two Pointers

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

📚 Hash Map

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

📊 Prefix Sum

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

🌐 BFS / Level-order

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

🧠 Dynamic Programming

Use when: optimal substructure + overlapping subproblems

→ Top-down: recursion + memoization
→ Bottom-up: tabulation (iterative)
Examples: Climbing Stairs, Coin Change, Longest Common Subsequence

🚀 Getting Started

Want to explore or run these solutions locally?

1️⃣ Clone the Repository

git clone https://github.com/Anjali56-creator/Leetcode-submissions.git
cd Leetcode-submissions

2️⃣ Compile and Run a C++ Solution

# Compile
g++ -o solution 0001-two-sum/solution.cpp

# Run
./solution

3️⃣ Recommended Setup

  • IDE: VS Code with C/C++ extension
  • Compiler: g++ (GCC 11+)
  • Online Judge: LeetCode for testing

🎯 Goals & Roadmap

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

🏆 Milestones

  • 50 problems solved
  • 100 problems solved
  • 200 problems solved
  • Complete Blind 75
  • Complete NeetCode 150
  • Achieve LeetCode Rating 1500+

📚 Resources I Use

📖 Books

  • Introduction to Algorithms (CLRS) — Cormen et al.
  • Competitive Programming 3 — Steven & Felix Halim
  • Cracking the Coding Interview — Gayle Laakmann McDowell

🌐 Online Platforms

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

🎥 YouTube Channels

  • NeetCode — Pattern explanations with clean C++ code
  • take U forward (Striver) — In-depth DSA in C++
  • Abdul Bari — Algorithm theory and intuition

🤝 Connect With Me

   

👩‍💻 Author

Anjali Kumari

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." 🚀


📄 License

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! 💪


⭐ If this repo helps you, give it a star and share it!

Keep solving. Keep growing. Keep shining.

LeetCode Topics

String

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

Simulation

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

Hash Table

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

Sliding Window

Problem Name Difficulty
0003-longest-substring-without-repeating-characters Medium

Array

Problem Name Difficulty
0015-3sum Medium
0048-rotate-image Medium
0153-find-minimum-in-rotated-sorted-array Medium
0154-find-minimum-in-rotated-sorted-array-ii Hard
0189-rotate-array Medium
0396-rotate-function Medium
1665-minimum-initial-energy-to-finish-tasks Hard
1848-minimum-distance-to-the-target-element Easy
1855-maximum-distance-between-a-pair-of-values Medium
1861-rotating-the-box Medium
1863-sum-of-all-subset-xor-totals Easy
2011-final-value-of-variable-after-performing-operations Easy
2016-maximum-difference-between-increasing-elements Easy
2037-minimum-number-of-moves-to-seat-everyone Easy
2078-two-furthest-houses-with-different-colors Easy
2089-find-target-indices-after-sorting-array Easy
2463-minimum-total-distance-traveled Hard
2515-shortest-distance-to-target-string-in-a-circular-array Easy
2540-minimum-common-value Easy
2553-separate-the-digits-in-an-array Easy
2615-sum-of-distances Medium
2657-find-the-prefix-common-array-of-two-arrays Medium
2770-maximum-number-of-jumps-to-reach-the-last-index Medium
2784-check-if-array-is-good Easy
2942-find-words-containing-character Easy
3653-xor-after-range-multiplication-queries-i Medium
3660-jump-game-ix Medium
3668-restore-finishing-order Easy
3701-compute-alternating-sum Easy

Divide and Conquer

Problem Name Difficulty
3653-xor-after-range-multiplication-queries-i Medium

Two Pointers

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

Sorting

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

Math

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

Binary Search

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

Dynamic Programming

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

Bit Manipulation

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

Greedy

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

Depth-First Search

Problem Name Difficulty
0547-number-of-provinces Medium

Breadth-First Search

Problem Name Difficulty
0547-number-of-provinces Medium

Union-Find

Problem Name Difficulty
0547-number-of-provinces Medium

Graph Theory

Problem Name Difficulty
0547-number-of-provinces Medium

Prefix Sum

Problem Name Difficulty
2615-sum-of-distances Medium

Counting

Problem Name Difficulty
2833-furthest-point-from-origin Easy

Counting Sort

Problem Name Difficulty
2037-minimum-number-of-moves-to-seat-everyone Easy

Linked List

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

Recursion

Problem Name Difficulty
0206-reverse-linked-list Easy
0234-palindrome-linked-list Easy

String Matching

Problem Name Difficulty
0796-rotate-string Easy

Matrix

Problem Name Difficulty
0048-rotate-image Medium
1861-rotating-the-box Medium

Stack

Problem Name Difficulty
0234-palindrome-linked-list Easy

Number Theory

Problem Name Difficulty
2807-insert-greatest-common-divisors-in-linked-list Medium

Backtracking

Problem Name Difficulty
1863-sum-of-all-subset-xor-totals Easy

Combinatorics

Problem Name Difficulty
1863-sum-of-all-subset-xor-totals Easy

Enumeration

Problem Name Difficulty
1863-sum-of-all-subset-xor-totals Easy

About

In this repo I will push the codes of the problems which I solve on LeetCode

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors