- This is a repository for my solutions to the problems on the platform Leetcode in the C++/CPP language.
-
Notes: "π" means your subscription of LeetCode premium membership is required for reading the question.
-
Difficulty Level: π’Easy, π Medium, π΄Hard
# | Title | Solution | Time | Space | Difficulty | Tag |
---|---|---|---|---|---|---|
1 | Two Sum | C++ | O(n2) | O(n) | π’ | Array, Hash Table |
8 | String to Integer (atoi) | C++ | O(n) | O(n) | π | Math, String |
20 | Valid Parentheses | C++ | O(n) | O(n) | π’ | String, Stack |
23 | Merge k Sorted Lists | C++ | O(n*logK) | O(K) | π΄ | Linked List, DnC, Heap |
32 | Longest Valid Parentheses | C++ | O(n) | O(1) | π΄ | String, DP |
37 | Sudoku Solver | C++ | O(9n*n) | O(n2) | π΄ | Hash Table, BackTracking |
53 | Maximum Subarray | C++ | O(n) | O(1) | π’ | Array, DnC, DP |
64 | Minimum Path Sum | C++ | O(mn) | O(n) | π | Array, DP, Matrix |
70 | Climbing Stairs | C++ | O(n) | O(1) | π’ | DP |
78 | Subsets | C++ | O(2^n+1) | O(2^n) | π | Array, Backtracking, Bit Manipulation |
89 | Gray Code | C++ | (2n) | (2n) | π | Math, BackTracking, Bit Manipulation |
90 | Subsets II | C++ | O(nlonn + 2^n+1) | O(2^n) | π | Array, Backtracking |
91 | Decode Ways | C++ | O(n) | O(1) | π | String, DP |
118 | Pascal's Triangle | C++ | (n2) | (n2) | π’ | Array, DP |
119 | Pascal's Triangle II | C++ | O(n) | O(n) | π’ | Array, DP |
121 | Best Time to Buy and Sell Stock | C++ | O(n) | O(1) | π’ | Array, DP |
133 | Clone Graph | C++ | O(n) | O(n) | π | Hash Table, DFS, BFS, Graph |
134 | Gas Station | C++ | O(n) | O(1) | π | Greedy |
138 | Copy List with Random Pointer | C++ | O(N) | O(N) | π΄ | Hash Table, Linked List |
139 | Word Break | C++ | O(n2) | O(n) | π | DP |
140 | Word Break II | C++ | O(M^N) | O(N) | π΄ | DP, BackTracking |
151 | Reverse Words in a String | C++ | O(n) | O(1) | π | String |
152 | Maximum Product Subarray | C++ | O(n) | O(1) | π | Array, DP |
174 | Dungeon Game | C++ | O(mn) | O(n) | π΄ | Array, DP, Matrix |
198 | House Robber | C++ | O(n) | O(1) | π | DP |
213 | House Robber II | C++ | O(n) | O(1) | π | DP |
215 | Kth Largest Element in an Array | C++ | O(n*logK) | O(K) | π | Array, DnC, Heap(PQ), Sorting, Quickselect |
256 | Paint Houseπ | C++ | O(n) | O(1) | π | DP |
264 | Ugly Number II | C++ | O(n*logn) | O(n) | π | Math, DP, Heap |
289 | Game of Life | C++ | O(mn) | O(1) | π | Array |
295 | Find Median from Data Stream | C++ | O(n*logn) | O(n) | π΄ | Heap, Design |
300 | Longest Increasing Subsequence | C++ | O(nlogn) | O(N) | π | Binary Search, DP |
303 | Range Sum Query - Immutable | C++ | O(n) | O(n) | π’ | DP |
309 | Best Time to Buy and Sell Stock with Cooldown | C++ | O(n) | O(1) | π | DP |
312 | Burst Balloons | C++ | O(n3) | O(n2) | π΄ | DnC, DP |
322 | Coin Change | C++ | O(n*amount) | O(amount) | π | DP |
334 | Increasing Triplet Subsequence | C++ | O(n) | O(1) | π | Adhoc |
338 | Counting Bits | C++ | O(n) | O(n) | π’ | DP, Bit Manipulation |
357 | Count Numbers with Unique Digits | C++ | O(n) | O(1) | π | Math, DP, Backtracking |
392 | Is Subsequence | C++ | O(n) | O(1) | π’ | Binary Search, DP, Greedy |
403 | Frog Jump | C++ | O(n2) | O(n2) | π΄ | Array, DP |
406 | Queue Reconstruction by Height | C++ | O(n2) | O(n) | π | Greedy |
456 | 132 Pattern | C++ | O(n) | O(n) | π | Stack |
516 | Longest Palindromic Subsequence | C++ | O(n2) | O(n) | π | DP |
518 | Coin Change 2 | C++ | O(n*amount) | O(amount) | π | DP |
547 | Friend Circles | C++ | O(n) | O(n) | π | DFS, BFS, Union Find, Graph |
566 | Reshape the Matrix | C++ | O(mn) | O(rc) | π’ | Array, Matrix, Simulation |
665 | Non-decreasing Array | C++ | O(n) | O(1) | π | Array |
714 | Best Time to Buy and Sell Stock with Transaction Fee | C++ | O(n) | O(1) | π | Array, DP, Greedy |
718 | Maximum Length of Repeated Subarray | C++ | O(nm) | O(m) | π | Array, Binary Search, DP, Sliding Window, Rolling Hash, Hash function |
746 | Min Cost Climbing Stairs | C++ | O(n) | O(1) | π’ | Array, DP |
792 | Number of Matching Subsequences | C++ | O(mlogn) | O(n) | π | Hash Table, String, Trie, Sorting |
877 | Stone Game | C++ | O(1) | O(1) | π | Math, DP, Minimax |
973 | K Closest Points to Origin | C++ | O(n + klogn) | O(n2) | π | DnC, Sort, Heap |
990 | Satisfiability of Equality Equations | C++ | O(n) | O(n) | π | Array, String, Union Find, Graph |
1025 | Divisor Game | C++ | O(1) | O(1) | π’ | Math, DP |
1027 | Longest Arithmetic Subsequence | C++ | O(n2) | O(n2) | π | DP |
1047 | Remove All Adjacent Duplicates In String | C++ | O(n) | O(n) | π’ | String, Stack |
1108 | Defanging an IP Address | C++ | O(n) | O(n) | π’ | String |
1220 | Count Vowels Permutation | C++ | O(n) | O(1) | π΄ | DP |
1313 | Decompress Run-Length Encoded List | C++ | O(n2) | O(n2) | π’ | Array |
1325 | Delete Leaves With a Given Value | C++ | O(n) | O(1) | π | Hash Table, Binary Tree, DFS, BFS |
1338 | Reduce Array Size to The Half | C++ | O(nlogn) | O(n) | π | Array, Hash Table, Greedy, Sorting, Heap(PQ) |
1402 | Reducing Dishes | C++ | O(nlogn) | O(1) | π΄ | DP |
1431 | Kids With the Greatest Number of Candies | C++ | O(n) | O(n) | π’ | Array |
1438 | Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit | C++ | O(n) | O(n) | π | Array, Sliding Window |
1470 | Shuffle the Array | C++ | O(n) | O(n) | π’ | Array |
1480 | Running Sum of 1d Array | C++ | O(n) | O(1) | π’ | Array |
1528 | Shuffle String | C++ | O(n) | O(n) | π’ | Array, String |
1641 | Count Sorted Vowel Strings | C++ | O(nk) | O(k) | π | Math, DP, Backtracking |
1689 | Partitioning Into Minimum Number Of Deci-Binary Numbers | C++ | O(n) | O(1) | π | Greedy |
1710 | Maximum Units on a Truck | C++ | O(nlogn) | O(1) | π’ | Greedy, Sort |
1720 | Decode XORed Array | C++ | O(n) | O(1) | π | Array, Bit Manipulation |
1859 | Sorting the Sentence | C++ | O(n) | O(n) | π’ | String, Sorting |
1860 | Incremental Memory Leak | C++ | O(n) | O(1) | π | Simulation |
1861 | Rotating the Box | C++ | O(n2) | O(n2) | π | Array, Two Pointer, Matrix |
1869 | Longer Contiguous Segments of Ones than Zeros | C++ | O(n) | O(1) | π’ | String |
1870 | Minimum Speed to Arrive on Time | C++ | O(nlog(1e7)) | O(1) | π | Array, Binary Search |
1876 | Substrings of Size Three with Distinct Characters | C++ | O(n) | O(1) | π’ | Hash Table, String, Sliding Window, Counting |
1877 | Minimize Maximum Pair Sum in Array | C++ | O(nlogn) | O(1) | π | Array, Two Pointer, Greedy, Sorting |
1878 | Get Biggest Three Rhombus Sums in a Grid | C++ | O(n4) | O(n) | π | Array, Math, Sorting, Heap(PQ), Matrix, Prefix Sum |
1880 | Check if Word Equals Summation of Two Words | C++ | O(n) | O(1) | π’ | String |
1881 | Maximum Value after Insertion | C++ | O(n) | O(1) | π | String, Greedy |
1886 | Determine Whether Matrix Can Be Obtained By Rotation | C++ | O(n) | O(1) | π’ | Array |
1887 | Reduction Operations to Make the Array Elements Equal | C++ | O(nlogn) | O(n) | π | Greedy, Sort |
1888 | Minimum Number of Flips to Make the Binary String Alternating | C++ | O(n) | O(1) | π | Array, Greedy |
1893 | Check if All the Integers in a Range Are Covered | C++ | O(n2) | O(n) | π’ | Greedy |
1894 | Find the Student that Will Replace the Chalk | C++ | O(n) | O(1) | π | Array, Greedy |
1895 | Largest Magic Square | C++ | O(m3n) | O(mn) | π | Array, DP |
1897 | Redistribute Characters to Make All Strings Equal | C++ | O(n2) | O(26) | π’ | String, Greedy |
1898 | Maximum Number of Removable Characters | C++ | O(nlogn) | O(n) | π | Binary Search |
1899 | Merge Triplets to Form Target Triplet | C++ | O(n) | O(1) | π | Greedy |
1903 | Largest Odd Number in String | C++ | O(n) | O(1) | π’ | Greedy |
1904 | The Number of Full Rounds You Have Played | C++ | O(1) | O(1) | π | String, Greedy |
1905 | Count Sub Islands | C++ | O(nm) | O(nm) | π | DFS, Union Find |
1909 | Remove One Element to Make the Array Strictly Increasing | C++ | O(n) | O(1) | π’ | Array |
1910 | Remove All Occurrences of a Substring | C++ | O(nm) | O(m) | π | String |
1911 | Maximum Alternating Subsequence Sum | C++ | O(n) | O(n) | π | DP |
1913 | Maximum Product Difference Between Two Pairs | C++ | O(nlogn) | O(1) | π’ | Sort |
1914 | Cyclically Rotating a Grid | C++ | O(n) | O(n) | π | Array |
1920 | Build Array from Permutation | C++ | O(n) | O(1) | π’ | Array, Simulation |
1921 | Eliminate Maximum Number of Monsters | C++ | O(nlogn) | O(1) | π | Array, Greedy, Sorting |
1922 | Count Good Numbers | C++ | O(logn) | O(1) | π | Math, Recursion |