/My-Leetcode-Solution-In-CPP

This is a repository for my solutions to the problems on the platform Leetcode in the C++/CPP language. Give a Star to this repository if you like the content and support me to make more valuable content for you. The link of the platform is given below πŸ‘‡

Primary LanguageC++MIT LicenseMIT

Total lines of code  Language  License  Contributions Welcome

LeetCode Algorithms with Solution

  • 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

⬆️ Back to Top