A curated collection of solved Data Structures & Algorithms problems from GeeksforGeeks, including Problem of the Day (POTD) submissions β all implemented in C++.
- About This Repository
- Repository Structure
- Folder Breakdown
- Topics Covered
- How to Contribute
- Git Hooks Setup
- Naming Convention
- License
This repository contains solutions for GFG problems organized by difficulty level. Each file is a self-contained C++ solution to a single problem. The goal is to:
- Build a reference library for common DSA patterns
- Track progress across difficulty levels
- Help others learn by reading clean, working solutions
| Folder | Description |
|---|---|
| π« School Problems | Foundational math, strings, I/O |
| π΅ Basic Problems | Arrays, linked lists, trees, basic patterns |
| π’ Easy Problems | Sorting, searching, BST, stack, queue |
| π‘ Medium Problems | DP, graphs, advanced trees, sliding window |
| π΄ Hard Problems | Complex DP, advanced graphs, segment trees |
GFG-Problems/
βββ School Problems/ # Foundational math, strings, I/O
βββ Basic Problems/ # Arrays, linked lists, trees, basic patterns
βββ Easy Problems/ # Sorting, searching, BST, stack, queue
βββ Medium Problems/ # DP, graphs, advanced trees, sliding window
βββ Hard Problems/ # Complex DP, advanced graphs, segment trees
βββ README.md
Count: 80+ problems
Beginner-level problems covering C++ fundamentals, basic math, and string manipulation.
| Topic | Example Problems |
|---|---|
| Math & Numbers | Armstrong Number, Palindrome of Number, Perfect Number, Simple Interest, GCD, nPr |
| Strings | Reverse A String, Remove Vowels, Lower/Upper Case, Count Camel Case Characters |
| Arrays & Matrix | Matrix Multiplication, Transpose 2D Matrix, Sum of Diagonals, Mean/Median of Array |
| Patterns | Printing Pattern Set 1, Triangle Shrinking Downwards, Pattern of Strings |
| Linked Lists | Print Linked List Elements |
| Miscellaneous | Series of AP/GP, Swap Kth Element, Combinational Logic, Java Switch Case |
π Path: School Problems
Count: 85+ problems
Covers core data structures and foundational algorithms.
| Topic | Example Problems |
|---|---|
| Arrays | Missing Number, Binary Array Sorting, Cyclically Rotate Array, Count Pair Sum |
| Strings | Anagram of String, Implement strstr, Merge Two Strings, Print First Letter of Every Word |
| Linked Lists | Linked List Insertion, Insert in Middle, Node at Given Index, Find Sum of Last N Nodes |
| Trees | Inorder/Preorder/Postorder Traversal, Count Leaves, Minimum Element in BST |
| Stack | Implement Stack using Array |
| Searching | Binary Search, First and Last Occurrences of X |
| Math | LCM and GCD, Power of 2, Power of Four, Factorial, Fibonacci |
| Patterns | Pattern 1β13 (multiple star/number patterns) |
| Miscellaneous | Leap Year, Logical Operators, C++ STL Vector |
π Path: Basic Problems
Count: 130+ problems
Introduces classic algorithm patterns and more complex data structures.
| Topic | Example Problems |
|---|---|
| Arrays | Move Zeroes to End, Rotate Array, Sort 0-1-2, Equilibrium Point, Second Largest |
| Strings | Palindrome String, Panagram Checking, Run Length Encoding, Reverse Words |
| Linked Lists | Detect Loop, Reverse Linked List, Merge Sorted LL, Delete Middle Node |
| Trees | Height of Binary Tree, Left/Right View, Level Order Traversal, Mirror Tree |
| BST | Check for BST, Kth Largest in BST, Print BST Elements in Range |
| Sorting | Bubble Sort, Selection Sort |
| Stack & Queue | Parentheses Checker, Delete Middle of Stack, Two Stacks |
| Searching | Binary Search variants, Floor in Sorted Array, Find Transition Point |
| Math | Juggler Sequence, Padovan Sequence, Nth Fibonacci Number |
| Matrix | Search in Matrix, Print Matrix in Snake Pattern, Unique Rows in Boolean Matrix |
| Patterns | Pattern 2β21 (various shapes) |
π Path: Easy Problems
Count: 160+ problems
Covers advanced techniques such as dynamic programming, greedy algorithms, and complex tree/graph operations.
| Topic | Example Problems |
|---|---|
| Dynamic Programming | 0/1 Knapsack, Longest Common Substring, Gold Mine, Pascal Triangle, Count Ways to Nth Stair |
| Greedy | Job Sequencing, Minimum Cost of Ropes, N Meetings in One Room, Maximum Tip Calculator |
| Linked Lists | Palindrome LL, Reverse in Groups, Flatten LL, Clone with Random Pointer (see Hard) |
| Trees | Diameter of Binary Tree, Diagonal Sum, Ancestors in BT, Boundary Traversal |
| BST | Lowest Common Ancestor, Pair Sum in BST, Flatten BST, Largest BST |
| Graphs | Shortest Path in Undirected/Weighted Graph |
| Arrays | Kadane's Algorithm, Count Inversions, Majority Element, Find Missing & Repeating |
| Strings | Implement Atoi, Validate IP Address, Smallest Distinct Window |
| Sliding Window | Longest Substring with K Uniques, Subarrays with Atmost K Distinct |
| Binary Search | Allocate Minimum Pages, Minimize Heights II, K-Sized Subarray Maximum |
| Math | Modular Exponentiation, Integral Points Inside Triangle, Prime Pair with Target Sum |
| Matrix | Left Rotate Matrix K Times, Search in Row-Column Sorted Matrix, Largest Square |
π Path: Medium Problems
Count: 27+ problems
The most challenging problems involving advanced algorithms and complex optimizations.
| Topic | Example Problems |
|---|---|
| Trees | Binary Tree to DLL, Burning Tree, Possible Paths in a Tree |
| DP | Edit Distance, Longest Valid Parentheses, Minimum Cost Path, Wildcard Pattern Matching |
| Graphs | Alien Dictionary, Maximum Connected Group |
| Linked Lists | Subtraction in Linked List, Clone LL with Random Pointer |
| Strings | Longest Prefix Suffix, Smallest Window Containing All Characters, The Palindrome Pattern |
| Arrays | Count Reverse Pairs, Count Smaller Elements, Median of 2 Sorted Arrays (Different Sizes) |
| Others | N Queen Problem, Split Array Largest Sum, Meeting Rooms III |
π Path: Hard Problems
| Data Structure / Algorithm | Difficulty Range |
|---|---|
| Arrays & Strings | School β Hard |
| Linked Lists (Singly, Doubly, Circular) | Basic β Hard |
| Stack & Queue | Basic β Medium |
| Binary Trees & BST | Basic β Hard |
| Graphs | Medium β Hard |
| Dynamic Programming | Medium β Hard |
| Greedy Algorithms | Easy β Medium |
| Sorting & Searching | Basic β Medium |
| Sliding Window & Two Pointers | Easy β Medium |
| Matrix Operations | School β Medium |
| Bit Manipulation | Easy β Medium |
| Math & Number Theory | School β Medium |
Contributions are welcome! Follow these steps:
git clone https://github.com/<your-username>/GFG-Problems.git
cd GFG-Problemsgit checkout -b add/<Problem_Name>- Place the file in the correct difficulty folder (
School Problems/,Basic Problems/,Easy Problems/,Medium Problems/, orHard Problems/) - Follow the naming convention below
- Make sure your file compiles without errors
g++ -std=c++17 -Wall -o test "Easy Problems/Your_Problem_Name.cpp"git add "Easy Problems/Your_Problem_Name.cpp"
git commit -m "Add: Your_Problem_Name (Easy)"
git push origin add/<Problem_Name>Open a PR against the main branch. Describe the problem, your approach, and the time/space complexity.
This repository includes automatic commit message formatting via git hooks. The hooks will:
-
prepare-commit-msgβ Auto-generates commit messages in the format:POTD DD-MM-YYYY : problem_nameExample:
POTD 07-07-2026 : Two Sum -
commit-msgβ Validates your commit message:- Ensures the message starts with
POTDor a capital letter - Minimum 5 characters long
- Allows merge/revert commits to bypass validation
- Ensures the message starts with
After cloning the repository, run the setup script:
bash setup-hooks.shOr manually set up hooks:
# Copy hooks from git_hooks/ to .git/hooks/
cp git_hooks/prepare-commit-msg .git/hooks/
cp git_hooks/commit-msg .git/hooks/
# Make them executable
chmod +x .git/hooks/prepare-commit-msg
chmod +x .git/hooks/commit-msgSimply commit as usual β the message will be auto-generated:
git add "Easy Problems/Your_Problem_Name.cpp"
git commit
# Message auto-populates: POTD 07-07-2026 : Your_Problem_NameNote: Git hooks are local and not pushed to GitHub. They need to be set up on each machine after cloning. The setup-hooks.sh script makes this easy!
File names follow this pattern:
Problem_Name_With_Underscores.cpp
Rules:
- Use underscores (
_) instead of spaces - Use Title_Case for each word
- Match the exact problem name from GFG as closely as possible
.cppextension only β do not commit.exeor compiled binaries
Examples:
β
Kadane's_Algorithm.cpp
β
Lowest_Common_Ancestor_in_a_BST.cpp
β
Reverse_a_linked_list.cpp
β kadanes algorithm.cpp
β solution1.cpp
β Kadane's_Algorithm.exe
This repository is for educational purposes. All problem statements belong to GeeksforGeeks. Solutions and code in this repository are open for learning and reference.
β If this repository helped you, consider starring it to help others find it!