Skip to content

Latest commit

 

History

History
164 lines (161 loc) · 36.6 KB

cpp.md

File metadata and controls

164 lines (161 loc) · 36.6 KB

LeetCode C++ Solutions

A collection of LeetCode problems implemented in C++ with detailed complexity analysis and explanations.

Solutions

# Problem Difficulty Pattern Time Space Explanation
18 4Sum Medium Binary Search O(log n) O(1) Explanation
22 Generate Parentheses Medium Backtracking O(n) O(1) Explanation
33 Search in Rotated Sorted Array Medium Binary Search O(log n) O(1) Explanation
48 Rotate Image Medium Math & Logic O(n²) O(1) Explanation
61 Rotate List Medium Two Pointers O(n) O(1) Explanation
153 Find Minimum in Rotated Sorted Array Medium Binary Search O(log n) O(1) Explanation
154 Find Minimum in Rotated Sorted Array II Hard Binary Search O(n) O(1) Explanation
278 First Bad Version Easy Two Pointers O(n) O(1) Explanation
283 Move Zeroes Easy Array / General O(n) O(1) Explanation
290 Word Pattern Easy Hash Map O(n) O(n) Explanation
292 Nim Game Easy Array / General O(n) O(1) Explanation
303 Range Sum Query - Immutable Easy Two Pointers O(n) O(1) Explanation
326 Power of Three Easy Array / General O(n) O(1) Explanation
338 Counting Bits Easy Binary Search O(n) O(1) Explanation
396 Rotate Function Medium Bit Manipulation O(n) O(1) Explanation
486 Predict the Winner Medium Dynamic Programming O(n) O(n) Explanation
567 Permutation in String Medium Backtracking O(n) O(1) Explanation
788 Rotated Digits Medium Binary Search O(n) O(1) Explanation
796 Rotate String Easy Math & Logic O(n) O(1) Explanation
877 Stone Game Medium Tree & Graph O(n) O(n) Explanation
1081 Smallest Subsequence of Distinct Characters Medium Monotonic Stack O(n) O(n) Explanation
1111 Maximum Nesting Depth of Two Valid Parentheses Strings Medium Stack & Queue O(n) O(n) Explanation
1117 Building H2O Medium Array / General O(n) O(1) Explanation
1140 Stone Game II Medium Dynamic Programming O(n) O(n) Explanation
1190 Reverse Substrings Between Each Pair of Parentheses Medium Stack & Queue O(n) O(n) Explanation
1195 Fizz Buzz Multithreaded Medium Array / General O(n) O(1) Explanation
1226 The Dining Philosophers Medium Array / General O(n) O(1) Explanation
1291 Sequential Digits Medium Prefix Sum O(n) O(n) Explanation
1297 Maximum Number of Occurrences of a Substring Medium Hash Map O(n) O(n) Explanation
1306 Jump Game III Medium Tree & Graph O(n) O(n) Explanation
1340 Jump Game V Hard Dynamic Programming O(n) O(n) Explanation
1345 Jump Game IV Hard Hash Map O(n) O(n) Explanation
1386 Cinema Seat Allocation Medium Hash Map O(n) O(n) Explanation
1588 Sum of All Odd Length Subarrays Easy Array / General O(n) O(1) Explanation
1592 Rearrange Spaces Between Words Easy Array / General O(n) O(1) Explanation
1598 Crawler Log Folder Easy Array / General O(n) O(1) Explanation
1603 Design Parking System Easy Array / General O(n) O(1) Explanation
1608 Special Array With X Elements Greater Than or Equal X Easy Array / General O(n) O(1) Explanation
1619 Mean of Array After Removing Some Elements Easy Two Pointers O(n) O(1) Explanation
1624 Largest Substring Between Two Equal Characters Easy Array / General O(n) O(1) Explanation
1629 Slowest Key Easy Two Pointers O(n) O(1) Explanation
1636 Sort Array by Increasing Frequency Easy Hash Map O(n) O(n) Explanation
1637 Widest Vertical Area Between Two Points Containing No Points Easy Two Pointers O(n) O(1) Explanation
1640 Check Array Formation Through Concatenation Easy Hash Map O(n) O(n) Explanation
1646 Get Maximum in Generated Array Easy Array / General O(n) O(1) Explanation
1652 Defuse the Bomb Easy Array / General O(n) O(1) Explanation
1653 Minimum Deletions to Make String Balanced Medium Array / General O(n) O(1) Explanation
1656 Design an Ordered Stream Easy Bit Manipulation O(n) O(1) Explanation
1662 Check If Two String Arrays are Equivalent Easy Array / General O(n) O(1) Explanation
1665 Minimum Initial Energy to Finish Tasks Hard Binary Search O(log n) O(1) Explanation
1668 Maximum Repeating Substring Easy Array / General O(n) O(1) Explanation
1672 Richest Customer Wealth Easy Array / General O(n) O(1) Explanation
1674 Minimum Moves to Make Array Complementary Medium Hash Map O(n) O(n) Explanation
1678 Goal Parser Interpretation Easy Array / General O(n) O(1) Explanation
1684 Count the Number of Consistent Strings Easy Two Pointers O(n) O(1) Explanation
1688 Count of Matches in Tournament Easy Stack & Queue O(n) O(n) Explanation
1694 Reformat Phone Number Easy Array / General O(n) O(1) Explanation
1700 Number of Students Unable to Eat Lunch Easy Stack & Queue O(n) O(n) Explanation
1704 Determine if String Halves Are Alike Easy Array / General O(n) O(1) Explanation
1710 Maximum Units on a Truck Easy Two Pointers O(n) O(1) Explanation
1716 Calculate Money in Leetcode Bank Easy Array / General O(n) O(1) Explanation
1717 Maximum Score From Removing Substrings Medium Two Pointers O(n) O(1) Explanation
1720 Decode XORed Array Easy Bit Manipulation O(n) O(1) Explanation
1725 Number Of Rectangles That Can Form The Largest Square Easy Stack & Queue O(n) O(n) Explanation
1736 Latest Time by Replacing Hidden Digits Easy Math & Logic O(n) O(1) Explanation
1742 Maximum Number of Balls in a Box Easy Two Pointers O(n) O(1) Explanation
1748 Sum of Unique Elements Easy Hash Map O(n) O(n) Explanation
1752 Check if Array Is Sorted and Rotated Easy Binary Search O(n) O(1) Explanation
1758 Minimum Changes To Make Alternating Binary String Easy Stack & Queue O(n) O(n) Explanation
1763 Longest Nice Substring Easy Two Pointers O(n) O(1) Explanation
1768 Merge Strings Alternately Easy Array / General O(n) O(1) Explanation
1773 Count Items Matching a Rule Easy Array / General O(n) O(1) Explanation
1779 Find Nearest Point That Has the Same X or Y Coordinate Easy Hash Map O(n) O(n) Explanation
1784 Check if Binary String Has at Most One Segment of Ones Easy Bit Manipulation O(n) O(1) Explanation
1790 Check if One String Swap Can Make Strings Equal Easy Array / General O(n) O(1) Explanation
1791 Find Center of Star Graph Easy Array / General O(n) O(1) Explanation
1796 Second Largest Digit in a String Easy Math & Logic O(n) O(1) Explanation
1800 Maximum Ascending Subarray Sum Easy Two Pointers O(n) O(1) Explanation
1805 Number of Different Integers in a String Easy Bit Manipulation O(n) O(1) Explanation
1807 Evaluate the Bracket Pairs of a String Medium Hash Map O(n) O(n) Explanation
1812 Determine Color of a Chessboard Square Easy Array / General O(n) O(1) Explanation
1816 Truncate Sentence Easy Array / General O(n) O(1) Explanation
1822 Sign of the Product of an Array Easy Array / General O(n) O(1) Explanation
1827 Minimum Operations to Make the Array Increasing Easy Hash Map O(n) O(n) Explanation
1832 Check if the Sentence Is Pangram Easy Array / General O(n) O(1) Explanation
1837 Sum of Digits in Base K Easy Math & Logic O(n) O(1) Explanation
1838 Frequency of the Most Frequent Element Medium Sliding Window O(n) O(1) Explanation
1844 Replace All Digits with Characters Easy Math & Logic O(n) O(1) Explanation
1848 Minimum Distance to the Target Element Easy Two Pointers O(n) O(1) Explanation
1854 Maximum Population Year Easy Stack & Queue O(n) O(n) Explanation
1859 Sorting the Sentence Easy Array / General O(n) O(1) Explanation
1861 Rotating the Box Medium Array / General O(n) O(1) Explanation
1863 Sum of All Subset XOR Totals Easy Backtracking O(n) O(1) Explanation
1869 Longer Contiguous Segments of Ones than Zeros Easy Array / General O(n) O(1) Explanation
1871 Jump Game VII Medium Prefix Sum O(n) O(n) Explanation
1876 Substrings of Size Three with Distinct Characters Easy Array / General O(n) O(1) Explanation
1880 Check if Word Equals Summation of Two Words Easy Array / General O(n) O(1) Explanation
1886 Determine Whether Matrix Can Be Obtained By Rotation Easy Stack & Queue O(n) O(n) Explanation
1893 Check if All the Integers in a Range Are Covered Easy Two Pointers O(n) O(1) Explanation
1896 Minimum Cost to Change the Final Value of Expression Hard Two Pointers O(n) O(1) Explanation
1897 Redistribute Characters to Make All Strings Equal Easy Array / General O(n) O(1) Explanation
1903 Largest Odd Number in String Easy Bit Manipulation O(n) O(1) Explanation
1909 Remove One Element to Make the Array Strictly Increasing Easy Hash Map O(n) O(n) Explanation
1910 Remove All Occurrences of a Substring Medium Array / General O(n) O(1) Explanation
1913 Maximum Product Difference Between Two Pairs Easy Hash Map O(n) O(n) Explanation
1914 Cyclically Rotating a Grid Medium Tree & Graph O(n) O(n) Explanation
1920 Build Array from Permutation Easy Backtracking O(n) O(1) Explanation
1925 Count Square Sum Triples Easy Array / General O(n) O(1) Explanation
1927 Sum Game Medium Array / General O(n) O(1) Explanation
1935 Maximum Number of Words You Can Type Easy Array / General O(n) O(1) Explanation
1941 Check if All Characters Have Equal Number of Occurrences Easy Hash Map O(n) O(n) Explanation
1945 Sum of Digits of String After Convert Easy Math & Logic O(n) O(1) Explanation
1952 Three Divisors Easy Array / General O(n) O(1) Explanation
1957 Delete Characters to Make Fancy String Easy Array / General O(n) O(1) Explanation
1961 Check If String Is a Prefix of Array Easy Prefix Sum O(n) O(n) Explanation
2029 Stone Game IX Medium Tree & Graph O(n) O(n) Explanation
2058 Find the Minimum and Maximum Number of Nodes Between Critical Points Medium Two Pointers O(n) O(1) Explanation
2081 Sum of k-Mirror Numbers Hard Two Pointers O(n) O(1) Explanation
2091 Removing Minimum and Maximum From Array Medium Array / General O(n) O(1) Explanation
2267 Check if There Is a Valid Parentheses String Path Hard Two Pointers O(n) O(1) Explanation
2354 Number of Excellent Pairs Hard Two Pointers O(n) O(1) Explanation
2434 Using a Robot to Print the Lexicographically Smallest String Medium Stack & Queue O(n) O(n) Explanation
2540 Minimum Common Value Easy Sliding Window O(n) O(1) Explanation
2553 Separate the Digits in an Array Easy Math & Logic O(n) O(1) Explanation
2589 Minimum Time to Complete All Tasks Hard Two Pointers O(n) O(1) Explanation
2657 Find the Prefix Common Array of Two Arrays Medium Prefix Sum O(n) O(n) Explanation
2696 Minimum String Length After Removing Substrings Easy Stack & Queue O(n) O(n) Explanation
2770 Maximum Number of Jumps to Reach the Last Index Medium Dynamic Programming O(n) O(n) Explanation
2784 Check if Array is Good Easy Array / General O(n) O(1) Explanation
2904 Shortest and Lexicographically Smallest Beautiful String Medium Two Pointers O(n) O(1) Explanation
2948 Make Lexicographically Smallest Array by Swapping Elements Medium Hash Map O(n) O(n) Explanation
2958 Length of Longest Subarray With at Most K Frequency Medium Sliding Window O(n) O(1) Explanation
3016 Minimum Number of Pushes to Type Word II Medium Two Pointers O(n) O(1) Explanation
3043 Find the Length of the Longest Common Prefix Medium Prefix Sum O(n) O(n) Explanation
3120 Count the Number of Special Characters I Easy Hash Map O(n) O(n) Explanation
3300 Minimum Element After Replacement With Digit Sum Easy Math & Logic O(n) O(1) Explanation
3302 Find the Lexicographically Smallest Valid Sequence Medium Hash Map O(n) O(n) Explanation
3310 Remove Methods From Project Medium Stack & Queue O(n) O(n) Explanation
3499 Maximize Active Section with Trade I Medium Two Pointers O(n) O(1) Explanation
3513 Number of Unique XOR Triplets I Medium Stack & Queue O(n) O(n) Explanation
3514 Number of Unique XOR Triplets II Medium Binary Search O(n) O(1) Explanation
3517 Smallest Palindromic Rearrangement I Medium Two Pointers O(n) O(1) Explanation
3568 Minimum Moves to Clean the Classroom Medium Sliding Window O(n) O(1) Explanation
3629 Minimum Jumps to Reach End via Prime Teleportation Medium Two Pointers O(n) O(1) Explanation
3660 Jump Game IX Medium Two Pointers O(n) O(1) Explanation
3702 Longest Subsequence With Non-Zero Bitwise XOR Medium Dynamic Programming O(n) O(n) Explanation
3720 Lexicographically Smallest Permutation Greater Than Target Medium Backtracking O(n) O(1) Explanation
3742 Maximum Path Score in a Grid Medium Two Pointers O(n) O(1) Explanation
3867 Sum of GCD of Formed Pairs Medium Two Pointers O(n) O(1) Explanation
3875 Construct Uniform Parity Array I Easy Binary Search O(n) O(1) Explanation
3876 Construct Uniform Parity Array II Medium Bit Manipulation O(n) O(1) Explanation
3881 Direction Assignments with Exactly K Visible People Medium Array / General O(n) O(1) Explanation
3953 Maximum Score with Co-Prime Element Hard Hash Map O(n) O(n) Explanation
3962 Maximum Subarray Sum After at Most K Swaps Hard Hash Map O(n) O(n) Explanation
4102 Count Valid Substrings I Medium Sliding Window O(n) O(1) Explanation
4104 Count Valid Substrings II Medium Two Pointers O(n) O(1) Explanation