Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 DSA Mastery

A comprehensive C++ practice repository for Data Structures & Algorithms

Arrays Β· Linked Lists Β· Trees Β· Graphs Β· Sorting Β· Searching Β· Recursion Β· Dynamic Programming


C++ Problems Topics LeetCode

Language License


tech stack icons


✨ Topics Covered

πŸ“¦ Data Structures

  • Arrays & 2D Arrays
  • Vectors & 2D Vectors
  • Linked Lists (Single, Double, Circular)
  • Stack & Queue (Circular, Deque)
  • Binary Tree & BST
  • Map & Set

βš™οΈ Algorithms

  • Sorting (Bubble, Insertion, Selection, Merge, Quick, Cycle)
  • Searching (Linear, Binary)
  • Recursion (Basics & Intermediate)
  • Bit Manipulation
  • Prefix Sum & Sliding Window
  • Pattern Problems

🧩 Problem Solving

  • LeetCode problems (DSA Sheet)
  • Product-based company questions
  • Service-based company questions
  • Mathematical problems
  • String manipulation
  • Pointer-based problems

πŸ“ Project Structure

Click to expand / collapse the full directory tree
DSA/
β”œβ”€β”€ CPP Basics/                          ← Foundational C++ programs
β”‚   β”œβ”€β”€ PrintHello.cpp
β”‚   β”œβ”€β”€ SumOf2Numbers.cpp
β”‚   β”œβ”€β”€ SimpleInterest.cpp
β”‚   β”œβ”€β”€ CircleArea.cpp
β”‚   └── ...40+ files
β”‚
β”œβ”€β”€ Conditional/                         ← Decision-making constructs
β”‚   β”œβ”€β”€ If Else/                         (21 problems)
β”‚   β”‚   β”œβ”€β”€ Calculator.cpp
β”‚   β”‚   β”œβ”€β”€ LeapYearOrNot.cpp
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ Switch/                          (16 problems)
β”‚   β”‚   β”œβ”€β”€ Calculator.cpp
β”‚   β”‚   └── ...
β”‚   └── Ternary/                         (10 problems)
β”‚       β”œβ”€β”€ GreatestAmong3.cpp
β”‚       └── ...
β”‚
β”œβ”€β”€ Loop/                                ← Iteration constructs
β”‚   β”œβ”€β”€ For Loop/                        (40+ problems)
β”‚   β”‚   β”œβ”€β”€ FibonacciSeries.cpp
β”‚   β”‚   β”œβ”€β”€ PrimeNumber.cpp
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ While Loop/                      (40+ problems)
β”‚   β”‚   └── ...
β”‚   └── Do While Loop/                   (30+ problems)
β”‚       └── ...
β”‚
β”œβ”€β”€ Functions/                           ← Function-based problems
β”‚   β”œβ”€β”€ Factorial.cpp
β”‚   β”œβ”€β”€ FindGCD.cpp
β”‚   β”œβ”€β”€ PalindromeOrNot.cpp
β”‚   └── ...50+ files
β”‚
β”œβ”€β”€ Pointers/                            ← Pointer concepts & usage
β”‚   β”œβ”€β”€ PointerIntro.cpp
β”‚   β”œβ”€β”€ DoublePointer.cpp
β”‚   β”œβ”€β”€ PassByReference.cpp
β”‚   β”œβ”€β”€ PassByValue.cpp
β”‚   └── ...25+ files
β”‚
β”œβ”€β”€ Array/                               ← 1D Array operations
β”‚   β”œβ”€β”€ MaximumElement.cpp
β”‚   β”œβ”€β”€ SecondMaximumElement.cpp
β”‚   β”œβ”€β”€ Subarray.cpp
β”‚   └── ...40+ files
β”‚
β”œβ”€β”€ Vector/                              ← STL Vector operations
β”‚   β”œβ”€β”€ VectorBasics.cpp
β”‚   β”œβ”€β”€ Sort0And1And2ByThreePointer.cpp
β”‚   β”œβ”€β”€ Merge2SortedArray.cpp
β”‚   └── ...60+ files
β”‚
β”œβ”€β”€ 2D Arrays/                           ← Matrix operations
β”‚   β”œβ”€β”€ TransposeOfMatrix.cpp
β”‚   β”œβ”€β”€ Rotate90Degree.cpp
β”‚   β”œβ”€β”€ SpiralModel.cpp
β”‚   β”œβ”€β”€ MatrixMultiplication.cpp
β”‚   └── ...25+ files
β”‚
β”œβ”€β”€ 2D Vectors/                          ← 2D Vector problems
β”‚   β”œβ”€β”€ PascalTriangle.cpp
β”‚   β”œβ”€β”€ SearchIn2DMatrix.cpp
β”‚   β”œβ”€β”€ SpiralMatrix.cpp
β”‚   └── ...16 files
β”‚
β”œβ”€β”€ String/                              ← String manipulation
β”‚   β”œβ”€β”€ Introduction/                    (20+ basics)
β”‚   β”‚   β”œβ”€β”€ ReverseFromIndex2To5.cpp
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ BulitInFunction/                 (11 STL string functions)
β”‚   β”‚   β”œβ”€β”€ Reverse.cpp
β”‚   β”‚   β”œβ”€β”€ Sort.cpp
β”‚   β”‚   └── ...
β”‚   └── Intermediate/                    (11 problems)
β”‚       β”œβ”€β”€ LongestCommonPrefix.cpp
β”‚       β”œβ”€β”€ ValidAnargam.cpp
β”‚       └── ...
β”‚
β”œβ”€β”€ Sorting/                             ← Sorting algorithms
β”‚   β”œβ”€β”€ Bubble Sort/                     (10 variants)
β”‚   β”‚   β”œβ”€β”€ IncreasingOrder.cpp
β”‚   β”‚   β”œβ”€β”€ OptimizedIncreasingOrder.cpp
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ Insertion Sort/                  (4 variants)
β”‚   β”œβ”€β”€ Selection Sort/                  (2 variants)
β”‚   └── Problems On Sorting/             (9 LeetCode problems)
β”‚       β”œβ”€β”€ KthLargestElementFirstApproach.cpp
β”‚       β”œβ”€β”€ MajorityElement.cpp
β”‚       └── ...
β”‚
β”œβ”€β”€ Advance Sorting/                     ← Advanced sorting techniques
β”‚   β”œβ”€β”€ Merge Sort/                      (5 problems)
β”‚   β”‚   β”œβ”€β”€ IncreasingOrderMergeSort.cpp
β”‚   β”‚   β”œβ”€β”€ CountInversionOptimized.cpp
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ Quick Sort/                      (3 variants)
β”‚   β”‚   β”œβ”€β”€ QuickSortByTakingStartEle.cpp
β”‚   β”‚   └── ...
β”‚   └── Cycle Sort/                      (5 problems)
β”‚       β”œβ”€β”€ MissingNumber.cpp
β”‚       β”œβ”€β”€ FindTheDuplicateNumber.cpp
β”‚       └── ...
β”‚
β”œβ”€β”€ Searching/                           ← Search algorithms
β”‚   β”œβ”€β”€ Linear Search/                   (8 problems)
β”‚   β”‚   β”œβ”€β”€ FindTargetElement.cpp
β”‚   β”‚   β”œβ”€β”€ LowerBound.cpp
β”‚   β”‚   └── ...
β”‚   └── Binary Search/                   (17 problems)
β”‚       β”œβ”€β”€ FindLowerBound.cpp
β”‚       β”œβ”€β”€ KokoEatingBananas.cpp
β”‚       β”œβ”€β”€ CapacityToShipPackagesWithinDDays.cpp
β”‚       └── ...
β”‚
β”œβ”€β”€ Recursion/                           ← Recursive problem solving
β”‚   β”œβ”€β”€ Basics/                          (14 problems)
β”‚   β”‚   β”œβ”€β”€ CalculateFactorial.cpp
β”‚   β”‚   β”œβ”€β”€ TowerOfHanoi.cpp
β”‚   β”‚   └── ...
β”‚   └── Intermediate/                    (45+ problems)
β”‚       β”œβ”€β”€ GenerateParentheses.cpp
β”‚       β”œβ”€β”€ PermutationSequence.cpp
β”‚       β”œβ”€β”€ MazePath.cpp
β”‚       └── ...
β”‚
β”œβ”€β”€ Diveinto Mathematics/                ← Math-based algorithms
β”‚   β”œβ”€β”€ Bitwise Operator/                (12 problems)
β”‚   β”‚   β”œβ”€β”€ NumberOfSetBits.cpp
β”‚   β”‚   β”œβ”€β”€ Find2UniqueElement.cpp
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ Prefix Sum/                      (18 problems)
β”‚   β”‚   β”œβ”€β”€ PrefixSum.cpp
β”‚   β”‚   β”œβ”€β”€ ProductOfArrayItself_Method1.cpp
β”‚   β”‚   └── ...
β”‚   └── Sliding Window/                  (10 problems)
β”‚       β”œβ”€β”€ MaximumSumOfSubarraySizeK.cpp
β”‚       β”œβ”€β”€ MinimumSizeSubarraySum.cpp
β”‚       └── ...
β”‚
β”œβ”€β”€ Bits Manipulation/                   ← Bit-level operations
β”‚   β”œβ”€β”€ PowerOf2.cpp
β”‚   β”œβ”€β”€ PowerOf4.cpp
β”‚   └── PartyOfCouples.cpp
β”‚
β”œβ”€β”€ Maths/                               ← Mathematical problems
β”‚   β”œβ”€β”€ CountPrimes.cpp
β”‚   β”œβ”€β”€ PerfectNumber.cpp
β”‚   β”œβ”€β”€ UglyNumber.cpp
β”‚   └── ...8 files
β”‚
β”œβ”€β”€ Pattern Problems/                    ← Pattern printing
β”‚   β”œβ”€β”€ Star Pattern/                    (13 patterns)
β”‚   β”‚   β”œβ”€β”€ Pyramid.cpp
β”‚   β”‚   β”œβ”€β”€ HollowPyramid.cpp
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ Numerical Pattern/               (17 patterns)
β”‚   β”‚   β”œβ”€β”€ NumberPattern1.cpp
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ Alphabet Pattern/
β”‚   β”‚   β”œβ”€β”€ Capital Letter/              (20 patterns)
β”‚   β”‚   └── Small Letter/               (15 patterns)
β”‚   └── Complex Pattern/                 (10 patterns)
β”‚       β”œβ”€β”€ DiamondStar.cpp
β”‚       β”œβ”€β”€ ArrowShaped.cpp
β”‚       └── ...
β”‚
β”œβ”€β”€ Single Linked List/                  ← Singly linked list
β”‚   β”œβ”€β”€ InsertInLinkedList.cpp
β”‚   β”œβ”€β”€ ReverseLinkedList.cpp
β”‚   β”œβ”€β”€ LinkedListCycle.cpp
β”‚   β”œβ”€β”€ Merge_K_SortedList.cpp
β”‚   └── ...50+ files
β”‚
β”œβ”€β”€ Double Linked List/                  ← Doubly linked list
β”‚   β”œβ”€β”€ AddElementsAtHead.cpp
β”‚   β”œβ”€β”€ ReverseDoubleLinkedList.cpp
β”‚   └── ...22 files
β”‚
β”œβ”€β”€ Circular Linked List/
β”‚   └── Circular Single Linked List/     (15 files)
β”‚       β”œβ”€β”€ All_InsertionOperation.cpp
β”‚       └── ...
β”‚
β”œβ”€β”€ Stack/                               ← Stack data structure
β”‚   β”œβ”€β”€ ImplementStackByArray.cpp
β”‚   β”œβ”€β”€ ImplementingStackUsingLinkedList.cpp
β”‚   β”œβ”€β”€ InfixToPostfixExpression.cpp
β”‚   β”œβ”€β”€ LargestRectangleInHistogram.cpp
β”‚   β”œβ”€β”€ MinStackWithMostOptimizedSolution.cpp
β”‚   └── ...60+ files
β”‚
β”œβ”€β”€ Queue/                               ← Queue data structure
β”‚   β”œβ”€β”€ ImplementQueueUsingArray.cpp
β”‚   β”œβ”€β”€ ImplementUsingLinkedList.cpp
β”‚   β”œβ”€β”€ PopEfficientImplementUsingStack.cpp
β”‚   β”œβ”€β”€ RevealCardsInIncreasingOrder.cpp
β”‚   └── ...35+ files
β”‚
β”œβ”€β”€ Circular Queue/
β”‚   β”œβ”€β”€ DesignCircularQueue.cpp
β”‚   └── CircularQueueImplementaionUsingVector.cpp
β”‚
β”œβ”€β”€ Dequeue/                             ← Double-ended queue
β”‚   β”œβ”€β”€ DequeImplementation.cpp
β”‚   β”œβ”€β”€ ImplementDequeUsingDoubleLinkedList.cpp
β”‚   β”œβ”€β”€ SlidingWindowMaximum.cpp
β”‚   └── ...14 files
β”‚
β”œβ”€β”€ Binary Tree/                         ← Binary tree problems
β”‚   β”œβ”€β”€ Basics/                          (15 problems)
β”‚   β”‚   β”œβ”€β”€ DiameterOfBinaryTree.cpp
β”‚   β”‚   β”œβ”€β”€ LowestCommonAncesorOfBinaryTree.cpp
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ Traversals/                      (15 traversal methods)
β”‚   β”‚   β”œβ”€β”€ BFS.cpp
β”‚   β”‚   β”œβ”€β”€ BinaryTreeLevelOrderTraversal.cpp
β”‚   β”‚   └── ...
β”‚   └── InterView Question/              (13 problems)
β”‚       β”œβ”€β”€ BinaryTreeLeftSideView.cpp
β”‚       β”œβ”€β”€ BoundaryTraversal.cpp
β”‚       └── ...
β”‚
β”œβ”€β”€ Binary Search Tree/                  ← BST problems
β”‚   β”œβ”€β”€ Basics/                          (8 problems)
β”‚   β”‚   β”œβ”€β”€ InsertIntoBinarySearchTree.cpp
β”‚   β”‚   β”œβ”€β”€ ValidateBinarySearchTree.cpp
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ Deletion/                        (9 problems)
β”‚   β”‚   β”œβ”€β”€ DeleteNodeInBST.cpp
β”‚   β”‚   └── ...
β”‚   └── Moris Traversal/                 (3 problems)
β”‚       β”œβ”€β”€ MorisTraversal.cpp
β”‚       └── FlattenBinaryTreeToLinkedList.cpp
β”‚
β”œβ”€β”€ Map/
β”‚   └── Basic/                           (6 operations)
β”‚       β”œβ”€β”€ InsertionType1.cpp
β”‚       β”œβ”€β”€ DeleteInMap.cpp
β”‚       └── ...
β”‚
β”œβ”€β”€ Set/
β”‚   β”œβ”€β”€ Basic/                           (6 operations)
β”‚   β”‚   β”œβ”€β”€ InsertionInSet.cpp
β”‚   β”‚   └── ...
β”‚   └── Leetcode/                        (2 problems)
β”‚
└── DSA Sheet/                           ← Curated interview problems
    β”œβ”€β”€ Product Based/
    β”‚   β”œβ”€β”€ Array & Numbers/
    β”‚   β”‚   └── majorityElement.cpp
    β”‚   └── String/
    β”‚       └── lengthOfLastWord.cpp
    └── Service Based/
        β”œβ”€β”€ Array & Numbers/
        β”‚   β”œβ”€β”€ containsDuplicate.cpp
        β”‚   └── majorityElement.cpp
        β”œβ”€β”€ Stack & Queue/
        β”‚   └── minStack.cpp
        β”œβ”€β”€ String/
        β”‚   └── lengthOfLastWord.cpp
        └── Two Pointer & Sliding Window/

πŸš€ Getting Started

Prerequisites

GCC VS Code

Compile & Run

# Compile a single file
g++ -std=c++17 -o output filename.cpp

# Run
./output

# Compile with warnings (recommended)
g++ -std=c++17 -Wall -Wextra -o output filename.cpp

Example

cd "Sorting/Merge Sort"
g++ -std=c++17 -o mergesort IncreasingOrderMergeSort.cpp
./mergesort

🧰 Topic Quick Reference

Topic Folder Problems
C++ Basics CPP Basics/ 40+
Conditionals Conditional/ 47
Loops Loop/ 110+
Functions Functions/ 50+
Pointers Pointers/ 25+
Arrays Array/ 40+
Vectors Vector/ 60+
2D Arrays 2D Arrays/ 25+
Strings String/ 42+
Sorting Sorting/ + Advance Sorting/ 30+
Searching Searching/ 25
Recursion Recursion/ 60+
Linked Lists Single/Double/Circular Linked List/ 90+
Stack Stack/ 60+
Queue Queue/ + Circular Queue/ + Dequeue/ 50+
Trees Binary Tree/ + Binary Search Tree/ 43
Math Maths/ + Diveinto Mathematics/ 40+
Patterns Pattern Problems/ 75+
DSA Sheet DSA Sheet/ Growing

🌍 Problem Sources

🟑 LeetCode πŸ“˜ Custom 🏒 Product Based πŸ—οΈ Service Based
Binary Search, Trees, DP Sorting, Patterns, Basics Arrays, Strings, Stack Arrays, Strings, Two Pointer

🀝 Contributing

# 1. Clone the repo
git clone <repo-url>
cd DSA

# 2. Create a topic branch
git checkout -b topic/<topic-name>

# 3. Add your solution
# Follow naming convention: PascalCase.cpp

# 4. Commit with a clear message
git add .
git commit -m "feat(binary-search): add KthSmallestInMatrix"

# 5. Push and open a PR
git push origin topic/<topic-name>

Naming convention: PascalCase.cpp β€” e.g., FindTheDuplicateNumber.cpp

Rule Requirement
βœ… File naming PascalCase.cpp
βœ… Folder placement Place in the correct topic folder
βœ… Code style Clean, readable, with comments where needed
βœ… Compilation Must compile with g++ -std=c++17

Made with ❀️ by Rahul Goswami

About

All questions I practiced to master data structure & algorithms

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages