Solutions of problems on leetcode in Sequence [C++]. Intuition behind the solution and optimization technique and time and space complexity analysis.
# | Title | Difficulty | Solution | Time Complexity | Space Complexity |
---|---|---|---|---|---|
1 | Two Sum | Easy | Solution | TC - O(N) | SC - O(N) |
2 | Add Two Numbers | Medium | Solution | TC-O(max(m,n)) | SC-O(max(m,n)) |
3 | Longest Substring Without Repeating Characters | Medium | Solution | TC - O(N) | SC - O(min(m,n)) |
4 | Median of Two Sorted Arrays | Hard | Solution | TC- O(log(min(m, n))) | SC-O(1) |
5 | Longest Palindromic Substring | Medium | Solution | TC-O(N*N) | SC-O(1) |
6 | ZigZag Conversion | Medium | Solution | ||
7 | Reverse Integer | Easy | Solution | ||
8 | String to Integer (atoi) | Medium | Solution | ||
9 | Palindrome Number | Easy | Solution | ||
10 | Regular Expression Matching | Hard | Solution | ||
11 | Container With Most Water | Medium | Solution | ||
12 | Integer to Roman | Medium | Solution | ||
13 | Roman to Integer | Easy | Solution | ||
14 | Longest Common Prefix | Easy | Solution | ||
15 | 3Sum | Medium | Solution | ||
16 | 3Sum Closest | Medium | Solution | ||
17 | Letter Combinations of a Phone Number | Medium | Solution | ||
18 | 4Sum | Medium | Solution | ||
19 | Remove Nth Node From End of List | Medium | Solution | ||
20 | Valid Parentheses | Easy | Solution | ||
21 | Merge Two Sorted Lists | Easy | Solution | ||
22 | Generate Parentheses | Medium | Solution | ||
23 | Merge k Sorted Lists | Hard | Solution | ||
24 | Swap Nodes in Pairs | Medium | Solution | ||
25 | Reverse Nodes in k-Group | Hard | Solution | ||
26 | Remove Duplicates from Sorted Array | Easy | Solution | ||
27 | Remove Element | Easy | Solution | ||
28 | Find the Index of the First Occurrence in a String | Medium | Solution | ||
29 | Divide Two Integers | Medium | Solution | ||
30 | Substring with Concatenation of All Words | Hard | Solution | ||
31 | Next Permutation | Medium | Solution | ||
32 | Longest Valid Parentheses | Hard | Solution | ||
33 | Search in Rotated Sorted Array | Medium | Solution | ||
34 | Find First and Last Position of Element in Sorted Array | Medium | Solution | ||
35 | Search Insert Position | Easy | Solution | ||
36 | Valid Sudoku | Medium | Solution | ||
37 | Sudoku Solver | Hard | Solution | ||
38 | Count and Say | Medium | Solution | ||
39 | Combination Sum | Medium | Solution | ||
40 | Combination Sum II | Medium | Solution | ||
41 | First Missing Positive | Hard | Solution | ||
42 | Trapping Rain Water | Hard | Solution | ||
43 | Multiply Strings | Medium | Solution | ||
44 | Wildcard Matching | Hard | Solution | ||
45 | Jump Game II | Medium | Solution | ||
46 | Permutations | Medium | Solution | ||
47 | Permutations II | Medium | Solution | ||
48 | Rotate Image | Medium | Solution | ||
49 | Group Anagrams | Medium | Solution | ||
50 | Pow(x, n) | Medium | Solution | ||
51 | N-Queens | Hard | Solution | ||
52 | N-Queens II | Hard | Solution | ||
53 | Maximum Subarray | Medium | Solution | ||
54 | Spiral Matrix | Medium | Solution | ||
55 | Jump Game | Medium | Solution | ||
56 | Merge Intervals | Medium | Solution | ||
57 | Insert Interval | Medium | Solution | ||
58 | Length of Last Word | Easy | Solution | ||
59 | Spiral Matrix II | Medium | Solution | ||
60 | Permutation Sequence | Hard | Solution | ||
61 | Rotate List | Medium | Solution | ||
62 | Unique Paths | Medium | Solution | ||
63 | Unique Paths II | Medium | Solution | ||
64 | Minimum Path Sum | Medium | Solution | ||
65 | Valid Number | Hard | Solution | ||
66 | Plus One | Easy | Solution | ||
67 | Add Binary | Easy | Solution | ||
68 | Text Justification | Hard | Solution | ||
69 | Sqrt(x) | Easy | Solution | ||
70 | Climbing Stairs | Easy | Solution | ||
71 | Simplify Path | Medium | Solution | ||
72 | Edit Distance | Hard | Solution | ||
73 | Set Matrix Zeroes | Medium | Solution | ||
74 | Search a 2D Matrix | Medium | Solution | ||
75 | Sort Colors | Medium | Solution | ||
76 | Minimum Window Substring | Hard | Solution | ||
77 | Combinations | Medium | Solution | ||
78 | Subsets | Medium | Solution | ||
79 | Word Search | Medium | Solution | ||
80 | Remove Duplicates from Sorted Array II | Medium | Solution | ||
81 | Search in Rotated Sorted Array II | Medium | Solution | ||
82 | Remove Duplicates from Sorted List II | Medium | Solution | ||
83 | Remove Duplicates from Sorted List | Easy | Solution | ||
84 | Largest Rectangle in Histogram | Hard | Solution | ||
85 | Maximal Rectangle | Hard | Solution | ||
86 | Partition List | Medium | Solution | ||
87 | Scramble String | Hard | Solution | ||
88 | Merge Sorted Array | Easy | Solution | ||
89 | Gray Code | Medium | Solution | ||
90 | Subsets II | Medium | Solution | ||
91 | Decode Ways | Medium | Solution | ||
92 | Reverse Linked List II | Medium | Solution | ||
93 | Restore IP Addresses | Medium | Solution | ||
94 | Binary Tree Inorder Traversal | Easy | Solution | ||
95 | Unique Binary Search Trees II | Medium | Solution | ||
96 | Unique Binary Search Trees | Medium | Solution | ||
97 | Interleaving String | Medium | Solution | ||
98 | Validate Binary Search Tree | Medium | Solution | ||
99 | Recover Binary Search Tree | Medium | Solution | ||
100 | Same Tree | Easy | Solution | ||
144 | Binary Tree Preorder Traversal | Easy | Solution | ||
149 | Max points on a Line | Hard | Solution | ||
198 | House robber | Medium | Solution | ||
443 | String Compression | Medium | Solution | ||
567 | Permutation in String | Medium | Solution | ||
723 | Candy Crush | Medium | Solution | ||
918 | Maximum Sum Circular Subarray | Medium | Solution | ||
946 | Validate stack sequence | Medium | Solution | ||
1071 | Greatest Common Divisor of Strings | Easy | Solution | ||
1137 | N-th Tribonacci Number | Easy | Solution | ||
1365 | How Many Numbers Are Smaller Than the Current Number | Easy | Solution | ||
1443 | Minimum Time to Collect All Apples in a Tree | Medium | Solution | ||
1748 | Sum of Unique Elements | Easy | Solution | ||
2068 | Check Whether Two Strings are Almost Equivalent | Easy | Solution | ||
2070 | Most Beautiful Item for Each Query | Medium | Solution | ||
2073 | Time Needed to Buy Tickets | Easy | Solution | ||
2423 | Remove Letter To Equalize Frequency | Easy | Solution | ||
2535 | Difference Between Element Sum and Digit Sum of an Array | Easy | Solution | ||
2537 | Count the Number of Good Subarrays | Medium | Solution | ||
2558 | Take Gifts From the Richest Pile | Easy | Solution | ||
2559 | Count Vowel Strings in Ranges | Medium | Solution |