Collection of LeetCode questions to ace the coding interview! - Created using LeetHub
leetcode
- Array- Easy level (Two Pointer)
Sr. No. | Problem | Topic | Difficulty Level | No. |
---|---|---|---|---|
26 | Remove duplicates from sorted array | Array, Two Pointers | Easy | 1 |
28 | Remove Element | Array, Two Pointers | Easy | 2 |
88 | Merge Sorted Array | Array, Two Pointers, Sorting | Easy | 3 |
170 | Two Sum III - Data structure design | Array, Hash Table, Two Pointers | Easy | 4 |
283 | Move Zeroes | Array, Two Pointers | Easy | 5 |
349 | Intersection of Two Arrays | Array, Hash Table, Two Pointers | Easy | 6 |
350 | Intersection of Two Arrays II | Array, Hash Table, Two Pointers | Easy | 7 |
455 | Assign Cookies | Array, Two Pointers, Greedy | Easy | 8 |
821 | Shortest Distance to a Character | Array, Two Pointers, String | Easy | 9 |
832 | Flipping an Image | Array, Two Pointers, Matrix | Easy | 10 |
905 | Sort Array By Parity | Array, Two Pointers, Sorting | Easy | 11 |
922 | Sort Array By Parity II | Array, Two Pointers, Sorting | Easy | 12 |
942 | DI String Match | Array, Two Pointers, String | Easy | 13 |
977 | Squares of a Sorted Array | Array, Two Pointers, Sorting | Easy | 14 |
1089 | Duplicate Zeros | Array, Two Pointers | Easy | 15 |
1346 | Check If N and Its Double Exist | Array, Hash Table, Two Pointers | Easy | 16 |
1385 | Find the Distance Value Between Two Arrays | Array, Two Pointers, Binary Search | Easy | 17 |
1826 | Faulty Sensor | Array, Two Pointers | Easy | 18 |
2108 | Find First Palindromic String in the Array | Array, Two Pointers, String | Easy | 19 |
2367 | Number of Arithmetic Triplets | Array, Hash Table, Two Pointers | Easy | 20 |
2441 | Largest Positive Integer That Exists With Its Negative | Array, Hash Table, Two Pointers | Easy | 21 |
2465 | Number of Distinct Averages | Array, Hash Table, Two Pointers | Easy | 22 |
2511 | Maximum Enemy Forts That Can Be Captured | Array, Two Pointers | Easy | 23 |
2540 | Minimum Common Value | Array, Hash Table, Two Pointers | Easy | 24 |
2562 | Find the Array Concatenation Value | Array, Two Pointers, Simulation | Easy | 25 |
2570 | Merge Two 2D Arrays by Summing Values | Array, Hash Table, Two Pointers | Easy | 26 |
(Sliding Window)
- Contains Duplicate II-Array,Hash Table,Sliding Window
- Maximum Average Subarray I-Array,Sliding Window
- Diet Plan Performance-Array,Sliding Window
- Minimum Difference Between Highest and Lowest of K Scores-Array,Sliding Window,Sorting
2.Array- Medium Level
- Container With Most Water-Array,Two Pointers,Greedy
- 3Sum-Array,Two Pointers,Sorting
- 3Sum Closest-Array,Two Pointers,Sorting
- 4Sum-Array,Two Pointers,Sorting
- Next Permutation-Array,Two Pointers
- Sort Colors-Array,Two Pointers,Sorting
- Remove Duplicates from Sorted Array II-Array,Two Pointers
- Two Sum II - Input Array Is Sorted-Array,Two Pointers,Binary Search
- Rotate Array-Array,Math,Two Pointers
- Shortest Word Distance II-Array,Hash Table,Two Pointers
- Flatten 2D Vector-Array,Two Pointers,Design
- Meeting Rooms II-Array,Two Pointers,Greedy,3+
- 3Sum Smaller-Array,Two Pointers,Binary Search,1+
- Find the Duplicate Number-Array,Two Pointers,Binary Search,1+
- Sort Transformed Array-Array,Math,Two Pointers,1+
- Circular Array Loop-Array,Hash Table,Two Pointers
- Heaters-Array,Two Pointers,Binary Search,1+
- Longest Uncommon Subsequence II-Array,Hash Table,Two Pointers,2+
- Longest Word in Dictionary through Deleting-Array,Two Pointers,String,1+
- K-diff Pairs in an Array-Array,Hash Table,Two Pointers,2+
- Shortest Unsorted Continuous Subarray-Array,Two Pointers,Stack,3+
- Valid Triangle Number-Array,Two Pointers,Binary Search,2+
- Find K Closest Elements-Array,Two Pointers,Binary Search,3+
- Candy Crush-Array,Two Pointers,Matrix,1+
- Number of Subarrays with Bounded Maximum-Array,Two Pointers
- Expressive Words-Array,Two Pointers,String
- Friends Of Appropriate Ages-Array,Two Pointers,Binary Search,1+
- Most Profit Assigning Work-Array,Two Pointers,Binary Search,2+
- Longest Mountain in Array-Array,Two Pointers,2+
- Advantage Shuffle-Array,Two Pointers,Greed,1+
- Boats to Save People-Array,Two Pointers,Greedy,1+
- 3Sum With Multiplicity-Array,Hash Table,Two Pointers,2+
- Bag of Tokens-Array,Two Pointers,Greedy,1+
- Pancake Sorting-Array,Two Pointers,Greedy,1+
- Interval List Intersections-Array,Two Pointers
- Moving Stones Until Consecutive II-Array,Math,Two Pointers,1+
- Longest String Chain-Array,Hash Table,Two Pointers,2+
- Meeting Scheduler-Array,Two Pointers,Sorting
- The k Strongest Values in an Array-Array,Two Pointers,Sorting
- Number of Subsequences That Satisfy the Given Sum Condition-Array,Two Pointers,Binary Search,1+
- Range Sum of Sorted Subarray Sums-Array,Two Pointers,Binary Search,1+
- Dot Product of Two Sparse Vectors-Array,Hash Table,Two Pointers,1+
- Shortest Subarray to be Removed to Make Array Sorted-Array,Two Pointers,Binary Search,2+
- Number of Ways Where Square of Number Is Equal to Product of Two Numbers-Array,Hash Table,Math,1+
- Max Number of K-Sum Pairs-Array,Hash Table,Two Pointers,1+
- Ways to Split Array Into Three Subarrays-Array,Two Pointers,Binary Search,1+
- Sentence Similarity III-Array,Two Pointers,String
- Maximum Distance Between a Pair of Values-Array,Two Pointers,Binary Search,1+
- Rotating the Box-Array,Two Pointers,Matrix
- Product of Two Run-Length Encoded Arrays-Array,Two Pointers
- Minimize Maximum Pair Sum in Array-Array,Two Pointers,Greedy,1+
- Watering Plants II-Array,Two Pointers,Simulation
- Rearrange Array Elements by Sign-Array,Two Pointers,Simulation
- Partition Array According to Given Pivot-Array,Two Pointers,Simulation
- Successful Pairs of Spells and Potions-Array,Two Pointers,Binary Search,1+
- The Latest Time to Catch a Bus-Array,Two Pointers,Binary Search,1+
- Divide Intervals Into Minimum Number of Groups-Array,Two Pointers,Greedy,3+
- Maximum Matching of Players With Trainers-Array,Two Pointers,Greedy,1+
- Merge Operations to Turn Array Into a Palindrome-Array,Two Pointers,Greedy
- Total Cost to Hire K Workers-Array,Two Pointers,2+
- Divide Players Into Teams of Equal Skill-Array,Hash Table,Two Pointers,1+
- Count the Number of Fair Pairs-Array,Two Pointers,Binary Search,1+
- Find the Maximum Number of Marked Indices-Array,Two Pointers,Binary Search,2+
- Maximize Greatness of an Array-Array,Two Pointers,Greedy,1+
(Sliding Window)
- Minimum Size Subarray Sum-Array,Binary Search,Sliding Window,1+
- Max Consecutive Ones II-Array,Dynamic Programming,Sliding Window
- Find K Closest Elements-Array,Two Pointers,Binary Search,3+
- Subarray Product Less Than K-Array,Sliding Window
- Maximum Length of Repeated Subarray-Array,Binary Search,4+
- Fruit Into Baskets-Array,Hash Table,Sliding Window
- Binary Subarrays With Sum-Array,Hash Table,Sliding Window,1+
- Longest Turbulent Subarray-Array,Dynamic Programming,Sliding Window
- Max Consecutive Ones III-Array,Binary Search,Sliding Window,1+
- Maximum Sum of Two Non-Overlapping Subarrays-Array,Dynamic Programming,Sliding Window
- Grumpy Bookstore Owner-Array,Sliding Window
- Minimum Swaps to Group All 1's Together-Array,Sliding Window
- Count Number of Nice Subarrays-Array,Hash Table,Math,1+
- Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold-Array,Sliding Window
- Maximum Points You Can Obtain from Cards-Array,Sliding Window,Prefix Sum
- Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit-Array,Queue,Sliding Window,3+
- Find Two Non-overlapping Sub-arrays Each With Target Sum-Array,Hash Table,Binary Search,2+
- Longest Subarray of 1's After Deleting One Element-Array,Dynamic Programming,Sliding Window
- Minimum Operations to Reduce X to Zero-Array,Hash Table,Binary Search,2+
- Maximum Erasure Value-Array,Hash Table,Sliding Window
- Jump Game VI-Array,Dynamic Programming,Queue,3+
- Frequency of the Most Frequent Element-Array,Binary Search,Greedy,3+
- Distinct Numbers in Each Subarray-Array,Hash Table,Sliding Window
- Kth Smallest Subarray Sum-Array,Binary Search,Sliding Window
- K Radius Subarray Averages-Array,Sliding Window
- Number of Unique Flavors After Sharing K Candies-Array,Hash Table,Sliding Window
- Minimum Swaps to Group All 1's Together II-Array,Sliding Window
- Minimum Consecutive Cards to Pick Up-Array,Hash Table,Sliding Window
- Longest Nice Subarray-Array,Bit Manipulation,Sliding Window
- Smallest Subarrays With Maximum Bitwise OR-Array,Binary Search,Bit Manipulation,1+
- Maximum Sum of Distinct Subarrays With Length K-Array,Hash Table,Sliding Window
- Count the Number of Good Subarrays-Array,Hash Table,Sliding Window
- Maximize Win From Two Segments-Array,Binary Search,Sliding Window
- Sliding Subarray Beauty-Array,Hash Table,Sliding Window
3.Array - Hard level (Two Pointer)
- Trapping Rain Water-Array,Two Pointers,3+
- Find K-th Smallest Pair Distance-Array,Two Pointers,Binary Search,1+
- Get the Maximum Score-Array,Two Pointers,2+
- Closest Subsequence Sum,Array,Two Pointers,3+
- Maximum Score of a Good Subarray-Array,Two Pointers,Binary Search,2+
- Partition Array Into Two Arrays to Minimize Sum Difference-Array,Two Pointers,Binary Search,4+
- Maximum Total Beauty of the Gardens-Array,Two Pointers,Binary Search,2+
(Sliding Window)
- Contains Duplicate III-Array,Sliding Window,Sorting,2+
- Sliding Window Maximum-Array,Queue,Sliding Window,2+
- Sliding Window Median-Array,Hash Table,Sliding Window,1+
- Smallest Range Covering Elements from K Lists-Array,Hash Table,Greedy,3+
- K Empty Slots-Array,Binary Indexed Tree,2+
- Shortest Subarray with Sum at Least K-Array,Binary Search,Queue,4+
- Subarrays with K Different Integers-Array,Hash Table,Sliding Window,1+
- Minimum Number of K Consecutive Bit Flips-Array,Bit Manipulation,Queue,2+
- Constrained Subsequence Sum-Array,Dynamic Programming,Queue,3+
- Max Value of Equation-Array,Queue,Sliding Window,2+
- Maximum Number of Visible Points-Array,Math,Geometry,2+
- Minimum Adjacent Swaps for K Consecutive Ones-Array,Greedy,Sliding Window,1+
- Maximum Fruits Harvested After at Most K Steps-Array,Binary Search,Sliding Window,1+
- Count Subarrays With Score Less Than K-Array,Binary Search,Sliding Window,1+
- Maximum Number of Robots Within Budget-Array,Binary Search,Queue,3+
- Count Subarrays With Fixed Bounds-Array,Queue,Sliding Window,1+
- Maximum Frequency Score of a Subarray-Array,Hash Table,Math,1+
- Maximize the Minimum Powered City-Array,Binary Search,Greedy,3+
Trees and Graphs:
https://leetcode.com/problems/tree-of-coprimes/ https://leetcode.com/problems/redundant-connection-ii/ https://leetcode.com/problems/minimum-score-after-removals-on-a-tree/ https://leetcode.com/problems/minimize-malware-spread/ https://leetcode.com/problems/is-graph-bipartite/ https://leetcode.com/problems/jump-game-iii/ https://leetcode.com/problems/all-nodes-distance-k-in-binary-tree/ https://leetcode.com/problems/detonate-the-maximum-bombs/ https://leetcode.com/problems/cycle-length-queries-in-a-tree/ https://leetcode.com/problems/count-subtrees-with-max-distance-between-cities/ https://leetcode.com/problems/binary-trees-with-factors/ (with DP) https://leetcode.com/problems/find-eventual-safe-states/ https://leetcode.com/problems/open-the-lock/ https://leetcode.com/problems/surrounded-regions/ https://leetcode.com/problems/minimize-the-total-price-of-the-trips/ https://leetcode.com/problems/create-components-with-same-value/ https://leetcode.com/problems/minimum-cost-to-reach-destination-in-time/ (+DP) https://leetcode.com/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/ https://leetcode.com/problems/minimum-score-after-removals-on-a-tree/ https://leetcode.com/problems/divide-nodes-into-the-maximum-number-of-groups/ BFS / DFS ( Shortest Paths )
https://leetcode.com/problems/minimum-genetic-mutation/ https://leetcode.com/problems/nearest-exit-from-entrance-in-maze/ https://leetcode.com/problems/shortest-path-in-binary-matrix/ https://leetcode.com/problems/maximum-number-of-points-from-grid-queries/ (with binary search) https://leetcode.com/problems/minimum-time-to-visit-a-cell-in-a-grid/ https://leetcode.com/problems/number-of-restricted-paths-from-first-to-last-node/ (with DP) https://leetcode.com/problems/bus-routes/ Hashmaps
https://leetcode.com/problems/sum-of-matrix-after-queries/ https://leetcode.com/problems/determine-if-two-strings-are-close/ https://leetcode.com/problems/design-movie-rental-system/ Binary Trees
https://leetcode.com/problems/linked-list-in-binary-tree/ https://leetcode.com/problems/step-by-step-directions-from-a-binary-tree-node-to-another/ https://leetcode.com/problems/find-bottom-left-tree-value/ https://leetcode.com/problems/add-one-row-to-tree/ https://leetcode.com/problems/insufficient-nodes-in-root-to-leaf-paths/ https://leetcode.com/problems/path-in-zigzag-labelled-binary-tree/ https://leetcode.com/problems/binary-tree-coloring-game/ https://leetcode.com/problems/number-of-good-leaf-nodes-pairs/ Bitwise Operations :
leetcode.com/problems/neighboring-bitwise-xor/ https://leetcode.com/problems/longest-nice-subarray/ https://leetcode.com/problems/find-kth-largest-xor-coordinate-value/ https://leetcode.com/problems/number-of-steps-to-reduce-a-number-in-binary-representation-to-one/ https://leetcode.com/problems/minimum-operations-to-form-subsequence-with-target-sum/ Recursion :
https://leetcode.com/problems/find-the-punishment-number-of-an-integer/ https://leetcode.com/problems/maximum-number-of-achievable-transfer-requests/ https://leetcode.com/problems/split-array-into-fibonacci-sequence/ https://leetcode.com/problems/numbers-with-same-consecutive-differences/ Sliding Window
https://leetcode.com/problems/maximum-sum-of-distinct-subarrays-with-length-k/ https://leetcode.com/problems/max-consecutive-ones-iii/ https://leetcode.com/problems/count-zero-request-servers/ https://leetcode.com/problems/continuous-subarrays/ https://leetcode.com/problems/maximize-the-confusion-of-an-exam/ https://leetcode.com/problems/length-of-the-longest-valid-substring/ Stack
https://leetcode.com/problems/number-of-visible-people-in-a-queue/ https://leetcode.com/problems/robot-collisions/ https://leetcode.com/problems/sum-of-subarray-minimums/ https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string-ii/ https://leetcode.com/problems/asteroid-collision/ https://leetcode.com/problems/largest-rectangle-in-histogram/ https://leetcode.com/problems/subarray-with-elements-greater-than-varying-threshold/ https://leetcode.com/problems/apply-operations-to-maximize-score/ https://leetcode.com/problems/beautiful-towers-ii/ Dynamic Programming
https://leetcode.com/problems/count-vowels-permutation/ (A medium level problem) https://leetcode.com/problems/russian-doll-envelopes/ https://leetcode.com/problems/maximum-alternating-subsequence-sum/ https://leetcode.com/problems/maximum-absolute-sum-of-any-subarray/ https://leetcode.com/problems/longest-arithmetic-subsequence/ https://leetcode.com/problems/tallest-billboard/ https://leetcode.com/problems/decremental-string-concatenation/ https://leetcode.com/problems/count-all-possible-routes/ https://leetcode.com/problems/sum-of-imbalance-numbers-of-all-subarrays/ https://leetcode.com/problems/knight-dialer/ https://leetcode.com/problems/longest-arithmetic-subsequence-of-given-difference/ https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended-ii/ https://leetcode.com/problems/number-of-longest-increasing-subsequence/ https://leetcode.com/problems/minimum-sideway-jumps/ https://leetcode.com/problems/minimum-ascii-delete-sum-for-two-strings/ https://leetcode.com/problems/minimum-difficulty-of-a-job-schedule/ https://leetcode.com/problems/student-attendance-record-ii/ Linked Lists
https://leetcode.com/problems/merge-in-between-linked-lists/ https://leetcode.com/problems/remove-nodes-from-linked-list/ https://leetcode.com/problems/delete-the-middle-node-of-a-linked-list/ https://leetcode.com/problems/split-linked-list-in-parts/ https://leetcode.com/problems/reverse-linked-list-ii/ Bitmasking DP
https://leetcode.com/problems/number-of-ways-to-stay-in-the-same-place-after-some-steps/ https://leetcode.com/problems/maximize-score-after-n-operations/ https://leetcode.com/problems/special-permutations/ https://leetcode.com/problems/minimum-number-of-work-sessions-to-finish-the-tasks/ https://leetcode.com/problems/find-longest-awesome-substring/ https://leetcode.com/problems/number-of-valid-words-for-each-puzzle/ (No DP) https://leetcode.com/problems/number-of-ways-to-wear-different-hats-to-each-other/ https://leetcode.com/problems/the-number-of-good-subsets/ Suffix and Prefix Array :
https://leetcode.com/problems/find-two-non-overlapping-sub-arrays-each-with-target-sum/ (Hashmaps) https://leetcode.com/problems/minimum-deletions-to-make-string-balanced/ https://leetcode.com/problems/minimum-cost-to-make-array-equal/ (with binary search) https://leetcode.com/problems/longest-subarray-of-1s-after-deleting-one-element/ https://leetcode.com/problems/minimum-index-of-a-valid-split/ https://leetcode.com/problems/grid-game/ https://leetcode.com/problems/max-chunks-to-make-sorted-ii/ https://leetcode.com/problems/maximum-fruits-harvested-after-at-most-k-steps/ https://leetcode.com/problems/minimum-penalty-for-a-shop/ https://leetcode.com/problems/132-pattern (with sets) DSU :
https://leetcode.com/problems/accounts-merge/ https://leetcode.com/problems/satisfiability-of-equality-equations/ https://leetcode.com/problems/process-restricted-friend-requests/ https://leetcode.com/problems/graph-connectivity-with-threshold/ https://leetcode.com/problems/making-a-large-island/ Binary Search :
https://leetcode.com/problems/snapshot-array/ https://leetcode.com/problems/range-frequency-queries/ https://leetcode.com/problems/maximum-number-of-removable-characters/ leetcode.com/problems/split-array-largest-sum/ https://leetcode.com/problems/maximize-the-confusion-of-an-exam/ https://leetcode.com/problems/smallest-range-covering-elements-from-k-lists/ https://leetcode.com/problems/find-k-th-smallest-pair-distance/ https://leetcode.com/problems/kth-smallest-number-in-multiplication-table/ https://leetcode.com/problems/minimum-limit-of-balls-in-a-bag/ Digit DP
https://leetcode.com/problems/count-of-integers/ https://leetcode.com/problems/non-negative-integers-without-consecutive-ones/ https://leetcode.com/problems/count-stepping-numbers-in-range/ https://leetcode.com/problems/count-special-integers/ Sorting :
https://leetcode.com/problems/movement-of-robots/ (prefix sums) https://leetcode.com/problems/put-marbles-in-bags/ https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons/ https://leetcode.com/problems/minimum-interval-to-include-each-query/ https://leetcode.com/problems/non-overlapping-intervals/ https://leetcode.com/problems/k-th-smallest-prime-fraction/ https://leetcode.com/problems/closest-room/ (binary search) String
https://leetcode.com/problems/lexicographically-smallest-string-after-substring-operation/ https://leetcode.com/problems/sum-of-scores-of-built-strings/ (hashing) https://leetcode.com/problems/maximum-repeating-substring/ https://leetcode.com/problems/longest-chunked-palindrome-decomposition/ https://leetcode.com/problems/shortest-palindrome/ https://leetcode.com/problems/maximum-deletions-on-a-string/ https://leetcode.com/problems/longest-duplicate-substring/ Counting
https://leetcode.com/problems/count-unique-characters-of-all-substrings-of-a-given-string/ https://leetcode.com/problems/sum-of-all-odd-length-subarrays/ https://leetcode.com/problems/count-anagrams/ Line Sweep
https://leetcode.com/problems/describe-the-painting/ https://leetcode.com/problems/my-calendar-iii/ https://leetcode.com/problems/number-of-flowers-in-full-bloom/ https://leetcode.com/problems/maximum-beauty-of-an-array-after-applying-operation/ https://leetcode.com/problems/divide-intervals-into-minimum-number-of-groups/ Re-rooting
https://leetcode.com/problems/count-number-of-possible-root-nodes/ https://leetcode.com/problems/difference-between-maximum-and-minimum-price-sum/ https://leetcode.com/problems/minimum-height-trees/ Trie
https://leetcode.com/problems/sum-of-prefix-scores-of-strings/ https://leetcode.com/problems/maximum-genetic-difference-query/ (Tree Query) https://leetcode.com/problems/prefix-and-suffix-search/