A collection of 374 solved LeetCode problems in C++, organized by difficulty. Whether you're preparing for coding interviews or sharpening your problem-solving skills, feel free to explore!
| Difficulty | Solved | Folder |
|---|---|---|
| π’ Easy | 168 | Easy Problems |
| π‘ Medium | 177 | Medium Problems |
| π΄ Hard | 29 | Hard Problems |
| Total | 374 |
This repository uses Git Hooks to automate and standardize commit messages. Hooks help maintain consistency across all commits.
Git hooks are scripts that run automatically at certain points in the Git workflow. In this repository, we use:
prepare-commit-msg: Automatically generates commit message templates with a consistent formatcommit-msg: Validates commit messages to ensure they meet minimum standards
Commit messages follow this format:
POTD DD-MM-YYYY : problem name [Easy | Medium | Hard]
Example:
POTD 1/06/2026 : Two Sum [Easy]
POTD 2/06/2026 : BST [Medium]
Run the setup script from the repository root:
bash setup-hooks.shThis script will:
- Create the
.git/hooks/directory if it doesn't exist - Copy the hook files from
git_hooks/to.git/hooks/ - Make the hooks executable with proper permissions
- Display confirmation messages
If you prefer to set up hooks manually:
# Copy hooks to git directory
cp git_hooks/prepare-commit-msg .git/hooks/prepare-commit-msg
cp git_hooks/commit-msg .git/hooks/commit-msg
# Make them executable
chmod +x .git/hooks/prepare-commit-msg
chmod +x .git/hooks/commit-msgOnce installed, the hooks work automatically:
# Simply commit as usual - the message will be auto-generated
git add .
git commit
# The hook will prompt you to confirm or edit the auto-generated messageprepare-commit-msg Hook:
- Runs before the commit message editor opens
- Auto-generates commit messages in the format:
LeetCode NNNN : Problem_Name - Extracts the problem number from the directory/file path
commit-msg Hook:
- Runs after you enter the commit message
- Validates that the message is at least 5 characters long
- Ensures messages follow the expected format
- Prevents empty or invalid commits
Hooks not running?
- Verify they are executable:
ls -l .git/hooks/ - Check that
setup-hooks.shcompleted successfully - Ensure you're in the repository root directory
Need to bypass hooks temporarily?
# Use --no-verify to skip hook validation
git commit --no-verifyHook files location:
- Shared hooks:
git_hooks/directory - Active hooks:
.git/hooks/directory (created by setup script) - Note:
.git/is local to your machine, not shared with others
π Bonus Easy Problems (unnumbered)
| Problem | Solution |
|---|---|
| Complement of Base 10 | C++ |
| Number of 1 Bits | C++ |
| Number Complement | C++ |
| Pascal's Triangle | C++ |
| Pascal's Triangle II | C++ |
| Sqrt Number (without built-in) | C++ |
| Subtract Product and Sum of Digits | C++ |
| Subarray Sum Equals Target | C++ |
π Bonus Medium Problems (unnumbered)
| Problem | Solution |
|---|---|
| 3Sum | C++ |
| Delete Kth Node from End | C++ |
| Distinct Array & Target Integer Combinations | C++ |
| Find All Duplicates in an Array | C++ |
| Reverse a Number | C++ |
| Rotate Array | C++ |
| Sort Colors (Dutch National Flag) | C++ |
π Bonus Hard Problems (unnumbered)
| Problem | Solution |
|---|---|
| Median of Two Sorted Arrays | C++ |
| Reverse Nodes in k-Group | C++ |
| Topic | Example Problems |
|---|---|
| Arrays & Hashing | Two Sum, Product of Array Except Self, Majority Element |
| Two Pointers | 3Sum Closest, Two Sum II, Move Zeroes, Boats to Save People |
| Sliding Window | Grumpy Bookstore Owner, Get Equal Substrings Within Budget |
| Binary Search | Search in Rotated Sorted Array, Find Peak Element, Binary Search |
| Linked Lists | Merge k Sorted Lists, Reverse Linked List, Linked List Cycle |
| Trees | Maximum Depth of Binary Tree, Path Sum, LCA, Serialize BST |
| Stacks | Valid Parentheses, Remove All Adjacent Duplicates |
| Sorting | Sort an Array, Sort List, Insertion Sort List |
| Bit Manipulation | Single Number, Counting Bits, XOR Queries |
| Dynamic Programming | Climbing Stairs, Fibonacci, Stone Game II, Domino Tiling |
| Greedy | Assign Cookies, Lemonade Change, IPO, Patching Array |
| Graphs | Path with Maximum Probability, Regions Cut By Slashes |
| Matrix | Spiral Matrix, Search a 2D Matrix, Toeplitz Matrix |
| Math | Factorial Trailing Zeroes, Power of Two/Three/Four |
| Strings | String Compression, Valid Anagram, Merge Strings Alternately |
-
Clone the repo
git clone <repo-url> cd LeetCode-Problems
-
Compile any solution
g++ -std=c++17 -o solution "Easy Problems/1_Two-sum.cpp" ./solution -
Browse by difficulty β use the tables above or navigate the folders directly.
Found a better approach? Want to add a new solution? PRs are welcome!
- Fork the repository
- Add your solution in the appropriate difficulty folder
- Follow the naming convention:
<number>_<Problem_Name>.cpp - Submit a pull request
β Star this repo if you find it helpful!