Skip to content

UdaySharmaGitHub/LeetCode-Problems

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

208 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ† LeetCode Solutions

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!

Language Easy Medium Hard


πŸ“Š Progress Overview

Difficulty Solved Folder
🟒 Easy 168 Easy Problems
🟑 Medium 177 Medium Problems
πŸ”΄ Hard 29 Hard Problems
Total 374

πŸ“š Table of Contents


🟒 Easy Problems

# Problem Solution
1 Two Sum C++
9 Palindrome Number C++
13 Roman to Integer C++
20 Valid Parentheses C++
21 Merge Two Sorted Lists C++
26 Remove Duplicates from Sorted Array C++
27 Remove Element C++
28 Find the Index of the First Occurrence in a String C++
35 Search Insert Position C++
58 Length of Last Word C++
66 Plus One C++
67 Add Binary C++
70 Climbing Stairs C++
83 Remove Duplicates from Sorted List C++
94 Binary Tree Inorder Traversal C++
100 Same Tree C++
101 Symmetric Tree C++
104 Maximum Depth of Binary Tree C++
110 Balanced Binary Tree C++
111 Minimum Depth of Binary Tree C++
112 Path Sum C++
121 Best Time to Buy and Sell Stock C++
125 Valid Palindrome C++
136 Single Number C++
141 Linked List Cycle C++
144 Binary Tree Preorder Traversal C++
145 Binary Tree Postorder Traversal C++
160 Intersection of Two Linked Lists C++
169 Majority Element C++
191 Number of 1 Bits C++
203 Remove Linked List Elements C++
205 Isomorphic Strings C++
206 Reverse Linked List C++
222 Count Complete Tree Nodes C++
231 Power of Two C++
234 Palindrome Linked List C++
242 Valid Anagram C++
257 Binary Tree Paths C++
258 Add Digits C++
268 Missing Number C++
278 First Bad Version C++
283 Move Zeroes C++
326 Power of Three C++
338 Counting Bits C++
342 Power of Four C++
344 Reverse String C++
345 Reverse Vowels of a String C++
349 Intersection of Two Arrays C++
350 Intersection of Two Arrays II C++
367 Valid Perfect Square C++
374 Guess Number Higher or Lower C++
383 Ransom Note C++
389 Find the Difference C++
404 Sum of Left Leaves C++
409 Longest Palindrome C++
414 Third Maximum Number C++
455 Assign Cookies C++
476 Number Complement C++
507 Perfect Number C++
509 Fibonacci Number C++
543 Diameter of Binary Tree C++
557 Reverse Words in a String III C++
590 N-ary Tree Postorder Traversal C++
594 Longest Harmonious Subsequence C++
628 Maximum Product of Three Numbers C++
700 Search in a Binary Search Tree C++
703 Kth Largest Element in a Stream C++
704 Binary Search C++
724 Find Pivot Index C++
744 Find Smallest Letter Greater Than Target C++
747 Largest Number At Least Twice of Others C++
766 Toeplitz Matrix C++
860 Lemonade Change C++
876 Middle of the Linked List C++
884 Uncommon Words from Two Sentences C++
917 Reverse Only Letters C++
977 Squares of a Sorted Array C++
1002 Find Common Characters C++
1047 Remove All Adjacent Duplicates In String C++
1051 Height Checker C++
1071 Greatest Common Divisor of Strings C++
1122 Relative Sort Array C++
1128 Number of Equivalent Domino Pairs C++
1137 N-th Tribonacci Number C++
1207 Unique Number of Occurrences C++
1287 Element Appearing More Than 25% In Sorted Array C++
1290 Convert Binary Number in a Linked List to Integer C++
1323 Maximum 69 Number C++
1351 Count Negative Numbers in a Sorted Matrix C++
1380 Lucky Numbers in a Matrix C++
1394 Find Lucky Integer in an Array C++
1422 Maximum Score After Splitting a String C++
1431 Kids With the Greatest Number of Candies C++
1460 Make Two Arrays Equal by Reversing Subarrays C++
1464 Maximum Product of Two Elements in an Array C++
1480 Running Sum of 1d Array C++
1512 Number of Good Pairs C++
1518 Water Bottles C++
1528 Shuffle String C++
1544 Make The String Great C++
1550 Three Consecutive Odds C++
1572 Matrix Diagonal Sum C++
1598 Crawler Log Folder C++
1608 Special Array With X Elements Greater Than or Equal X C++
1614 Maximum Nesting Depth of the Parentheses C++
1624 Largest Substring Between Two Equal Characters C++
1636 Sort Array by Increasing Frequency C++
1662 Check If Two String Arrays are Equivalent C++
1684 Count the Number of Consistent Strings C++
1688 Count of Matches in Tournament C++
1700 Number of Students Unable to Eat Lunch C++
1704 Determine if String Halves Are Alike C++
1716 Calculate Money in Leetcode Bank C++
1732 Find the Highest Altitude C++
1748 Sum of Unique Elements C++
1752 Check if Array Is Sorted and Rotated C++
1768 Merge Strings Alternately C++
1791 Find Center of Star Graph C++
1832 Check if the Sentence Is Pangram C++
1863 Sum of All Subset XOR Totals C++
1894 Find the Student that Will Replace the Chalk C++
1920 Build Array from Permutation C++
1945 Sum of Digits of String After Convert C++
1957 Delete Characters to Make Fancy String C++
1979 Find Greatest Common Divisor of Array C++
2000 Reverse Prefix of Word C++
2022 Convert 1D Array Into 2D Array C++
2037 Minimum Number of Moves to Seat Everyone C++
2053 Kth Distinct String in an Array C++
2073 Time Needed to Buy Tickets C++
2094 Finding 3-Digit Even Numbers C++
2108 Find First Palindromic String in the Array C++
2124 Check if All A's Appears Before All B's C++
2210 Count Hills and Valleys in an Array C++
2215 Find the Difference of Two Arrays C++
2220 Minimum Bit Flips to Convert Number C++
2248 Intersection of Multiple Arrays C++
2264 Largest 3-Same-Digit Number in String C++
2331 Evaluate Boolean Binary Tree C++
2418 Sort the People C++
2441 Largest Positive Integer That Exists With Its Negative C++
2485 Find the Pivot Integer C++
2540 Minimum Common Value C++
2582 Pass the Pillow C++
2678 Number of Senior Citizens C++
2706 Buy Two Chocolates C++
2778 Sum of Squares of Special Elements C++
2839 Check if Strings Can be Made Equal With Operations I C++
2946 Matrix Similarity After Cyclic Shifts C++
2980 Check if Bitwise OR Has Trailing Zeros C++
3005 Count Elements With Maximum Frequency C++
3110 Score of a String C++
3136 Valid Word C++
3162 Find the Number of Good Pairs I C++
3184 Count Pairs That Form a Complete Day I C++
3190 Find Minimum Operations to Make All Elements Divisible by Three C++
3194 Minimum Average of Smallest and Largest Elements C++
3304 Find the K-th Character in String Game I C++
3330 Find the Original Typed String I C++
3487 Maximum Unique Subarray Sum After Deletion C++
πŸ“„ 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++

🟑 Medium Problems

# Problem Solution
2 Add Two Numbers C++
8 String to Integer (atoi) C++
16 3Sum Closest C++
24 Swap Nodes in Pairs C++
33 Search in Rotated Sorted Array C++
34 Find First and Last Position of Element in Sorted Array C++
40 Combination Sum II C++
53 Maximum Subarray C++
54 Spiral Matrix C++
59 Spiral Matrix II C++
61 Rotate List C++
74 Search a 2D Matrix C++
78 Subsets C++
81 Search in Rotated Sorted Array II C++
88 Merge Sorted Array C++
90 Subsets II C++
98 Validate Binary Search Tree C++
102 Binary Tree Level Order Traversal C++
103 Binary Tree Zigzag Level Order Traversal C++
105 Construct Binary Tree from Preorder and Inorder Traversal C++
106 Construct Binary Tree from Inorder and Postorder Traversal C++
107 Binary Tree Level Order Traversal II C++
113 Path Sum II C++
129 Sum Root to Leaf Numbers C++
137 Single Number II C++
142 Linked List Cycle II C++
147 Insertion Sort List C++
148 Sort List C++
153 Find Minimum in Rotated Sorted Array C++
162 Find Peak Element C++
164 Maximum Gap C++
165 Compare Version Numbers C++
167 Two Sum II C++
172 Factorial Trailing Zeroes C++
179 Largest Number C++
199 Binary Tree Right Side View C++
201 Bitwise AND of Numbers Range C++
204 Count Primes C++
215 Kth Largest Element in an Array C++
219 Contains Duplicate II C++
229 Majority Element II C++
230 Kth Smallest Element in a BST C++
235 Lowest Common Ancestor of a BST C++
236 Lowest Common Ancestor of a Binary Tree C++
237 Delete Node in a Linked List C++
238 Product of Array Except Self C++
240 Search a 2D Matrix II C++
241 Different Ways to Add Parentheses C++
260 Single Number III C++
264 Ugly Number II C++
287 Find the Duplicate Number C++
328 Odd Even Linked List C++
334 Increasing Triplet Subsequence C++
371 Sum of Two Integers C++
378 Kth Smallest Element in a Sorted Matrix C++
421 Maximum XOR of Two Numbers in an Array C++
437 Path Sum III C++
442 Find All Duplicates in an Array C++
443 String Compression C++
445 Add Two Numbers II C++
449 Serialize and Deserialize BST C++
515 Find Largest Value in Each Tree Row C++
523 Continuous Subarray Sum C++
539 Minimum Time Difference C++
592 Fraction Addition and Subtraction C++
624 Maximum Distance in Arrays C++
633 Sum of Square Numbers C++
637 Average of Levels in Binary Tree C++
648 Replace Words C++
650 2 Keys Keyboard C++
678 Valid Parenthesis String C++
725 Split Linked List in Parts C++
790 Domino and Tromino Tiling C++
791 Custom Sort String C++
826 Most Profit Assigning Work C++
837 New 21 Game C++
838 Push Dominoes C++
840 Magic Squares In Grid C++
846 Hand of Straights C++
852 Peak Index in a Mountain Array C++
874 Walking Robot Simulation C++
880 Decoded String at Index C++
881 Boats to Save People C++
885 Spiral Matrix III C++
898 Bitwise ORs of Subarrays C++
912 Sort an Array C++
945 Minimum Increment to Make Array Unique C++
947 Most Stones Removed with Same Row or Column C++
959 Regions Cut By Slashes C++
974 Subarray Sums Divisible by K C++
988 Smallest String Starting From Leaf C++
1007 Minimum Domino Rotations For Equal Row C++
1008 Construct BST from Preorder Traversal C++
1038 BST to Greater Sum Tree C++
1052 Grumpy Bookstore Owner C++
1105 Filling Bookcase Shelves C++
1110 Delete Nodes And Return Forest C++
1140 Stone Game II C++
1190 Reverse Substrings Between Each Pair of Parentheses C++
1208 Get Equal Substrings Within Budget C++
1233 Remove Sub-Folders from the Filesystem C++
1248 Count Number of Nice Subarrays C++
1249 Minimum Remove to Make Valid Parentheses C++
1296 Divide Array in Sets of K Consecutive Numbers C++
1310 XOR Queries of a Subarray C++
1325 Delete Leaves With a Given Value C++
1334 Find the City With the Smallest Number of Neighbors C++
1347 Minimum Number of Steps to Make Two Strings Anagram C++
1367 Linked List in Binary Tree C++
1371 Find the Longest Substring Containing Vowels in Even Counts C++
1382 Balance a Binary Search Tree C++
1395 Count Number of Teams C++
1438 Longest Continuous Subarray With Absolute Diff ≀ Limit C++
1482 Minimum Number of Days to Make m Bouquets C++
1498 Number of Subsequences That Satisfy the Given Sum Condition C++
1508 Range Sum of Sorted Subarray Sums C++
1509 Minimum Difference Between Largest and Smallest Value in Three Moves C++
1514 Path with Maximum Probability C++
1530 Number of Good Leaf Nodes Pairs C++
1552 Magnetic Force Between Two Balls C++
1605 Find Valid Matrix Given Row and Column Sums C++
1657 Determine if Two Strings Are Close C++
1679 Max Number of K-Sum Pairs C++
1685 Sum of Absolute Differences in a Sorted Array C++
1695 Maximum Erasure Value C++
1701 Average Waiting Time C++
1717 Maximum Score From Removing Substrings C++
1823 Find the Winner of the Circular Game C++
1905 Count Sub Islands C++
1910 Remove All Occurrences of a Substring C++
1937 Maximum Number of Points with Cost C++
1948 Delete Duplicate Folders in System C++
2028 Find Missing Observations C++
2044 Count Number of Maximum Bitwise-OR Subsets C++
2058 Find the Min and Max Number of Nodes Between Critical Points C++
2096 Step-By-Step Directions From a Binary Tree Node to Another C++
2125 Number of Laser Beams in a Bank C++
2134 Minimum Swaps to Group All 1's Together II C++
2181 Merge Nodes in Between Zeros C++
2192 All Ancestors of a Node in a DAG C++
2196 Create Binary Tree From Descriptions C++
2285 Maximum Total Importance of Roads C++
2326 Spiral Matrix IV C++
2348 Number of Zero-Filled Subarrays C++
2390 Removing Stars From a String C++
2402 Meeting Rooms III C++
2410 Maximum Matching of Players With Trainers C++
2411 Smallest Subarrays With Maximum Bitwise OR C++
2419 Longest Subarray With Maximum Bitwise AND C++
2486 Append Characters to String to Make Subsequence C++
2487 Remove Nodes From Linked List C++
2807 Insert Greatest Common Divisors in Linked List C++
2816 Double a Number Represented as a Linked List C++
2870 Minimum Number of Operations to Make Array Empty C++
2918 Minimum Equal Sum of Two Arrays After Replacing Zeros C++
2976 Minimum Cost to Convert String I C++
3016 Minimum Number of Pushes to Type Word II C++
3075 Maximize Happiness of Selected Children C++
3164 Find the Number of Good Pairs II C++
3185 Count Pairs That Form a Complete Day II C++
3191 Minimum Operations to Make Binary Array Elements Equal to One I C++
3201 Find the Maximum Length of Valid Subsequence I C++
3202 Find the Maximum Length of Valid Subsequence II C++
3217 Delete Nodes From Linked List Present in Array C++
3341 Find Minimum Time to Reach Last Room I C++
3342 Find Minimum Time to Reach Last Room II C++
3439 Reschedule Meetings for Maximum Free Time I C++
3440 Reschedule Meetings for Maximum Free Time II C++
3546 Equal Sum Grid Partition I 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++

πŸ”΄ Hard Problems

# Problem Solution
23 Merge k Sorted Lists C++
154 Find Minimum in Rotated Sorted Array II C++
220 Contains Duplicate III C++
273 Integer to English Words C++
330 Patching Array C++
502 IPO C++
564 Find the Closest Palindrome C++
664 Strange Printer C++
679 24 Game C++
719 Find K-th Smallest Pair Distance C++
726 Number of Atoms C++
995 Minimum Number of K Consecutive Bit Flips C++
1568 Minimum Number of Days to Disconnect Island C++
1579 Remove Max Number of Edges to Keep Graph Fully Traversable C++
1900 The Earliest and Latest Rounds Where Players Compete C++
2045 Second Minimum Time to Reach Destination C++
2071 Maximum Number of Tasks You Can Assign C++
2163 Minimum Difference in Sums After Removal of Elements C++
2322 Minimum Score After Removals on a Tree C++
2392 Build a Matrix With Conditions C++
2699 Modify Graph Edge Weights C++
2751 Robot Collisions C++
3307 Find the K-th Character in String Game II C++
3333 Find the Original Typed String II C++
3343 Count Number of Balanced Permutations C++
3363 Find the Maximum Number of Fruits Collected C++
3480 Maximize Subarrays After Removing One Conflicting Pair C++
πŸ“„ Bonus Hard Problems (unnumbered)
Problem Solution
Median of Two Sorted Arrays C++
Reverse Nodes in k-Group C++

πŸ—‚ Topics Covered

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

πŸš€ How to Use

  1. Clone the repo

    git clone <repo-url>
    cd LeetCode-Problems
  2. Compile any solution

    g++ -std=c++17 -o solution "Easy Problems/1_Two-sum.cpp"
    ./solution
  3. Browse by difficulty β€” use the tables above or navigate the folders directly.


🀝 Contributing

Found a better approach? Want to add a new solution? PRs are welcome!

  1. Fork the repository
  2. Add your solution in the appropriate difficulty folder
  3. Follow the naming convention: <number>_<Problem_Name>.cpp
  4. Submit a pull request

⭐ Star this repo if you find it helpful!

Releases

No releases published

Packages

 
 
 

Contributors

Languages