Skip to content

Collection of LeetCode questions to ace the coding interview! - Created using [LeetHub](https://github.com/QasimWani/LeetHub)

Notifications You must be signed in to change notification settings

Anamicca23/Leetcode-for-DSA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Leetcode-for-DSA

Collection of LeetCode questions to ace the coding interview! - Created using LeetHub

leetcode

  1. 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)

  1. Contains Duplicate II-Array,Hash Table,Sliding Window
  2. Maximum Average Subarray I-Array,Sliding Window
  3. Diet Plan Performance-Array,Sliding Window
  4. Minimum Difference Between Highest and Lowest of K Scores-Array,Sliding Window,Sorting

2.Array- Medium Level

  1. Container With Most Water-Array,Two Pointers,Greedy
  2. 3Sum-Array,Two Pointers,Sorting
  3. 3Sum Closest-Array,Two Pointers,Sorting
  4. 4Sum-Array,Two Pointers,Sorting
  5. Next Permutation-Array,Two Pointers
  6. Sort Colors-Array,Two Pointers,Sorting
  7. Remove Duplicates from Sorted Array II-Array,Two Pointers
  8. Two Sum II - Input Array Is Sorted-Array,Two Pointers,Binary Search
  9. Rotate Array-Array,Math,Two Pointers
  10. Shortest Word Distance II-Array,Hash Table,Two Pointers
  11. Flatten 2D Vector-Array,Two Pointers,Design
  12. Meeting Rooms II-Array,Two Pointers,Greedy,3+
  13. 3Sum Smaller-Array,Two Pointers,Binary Search,1+
  14. Find the Duplicate Number-Array,Two Pointers,Binary Search,1+
  15. Sort Transformed Array-Array,Math,Two Pointers,1+
  16. Circular Array Loop-Array,Hash Table,Two Pointers
  17. Heaters-Array,Two Pointers,Binary Search,1+
  18. Longest Uncommon Subsequence II-Array,Hash Table,Two Pointers,2+
  19. Longest Word in Dictionary through Deleting-Array,Two Pointers,String,1+
  20. K-diff Pairs in an Array-Array,Hash Table,Two Pointers,2+
  21. Shortest Unsorted Continuous Subarray-Array,Two Pointers,Stack,3+
  22. Valid Triangle Number-Array,Two Pointers,Binary Search,2+
  23. Find K Closest Elements-Array,Two Pointers,Binary Search,3+
  24. Candy Crush-Array,Two Pointers,Matrix,1+
  25. Number of Subarrays with Bounded Maximum-Array,Two Pointers
  26. Expressive Words-Array,Two Pointers,String
  27. Friends Of Appropriate Ages-Array,Two Pointers,Binary Search,1+
  28. Most Profit Assigning Work-Array,Two Pointers,Binary Search,2+
  29. Longest Mountain in Array-Array,Two Pointers,2+
  30. Advantage Shuffle-Array,Two Pointers,Greed,1+
  31. Boats to Save People-Array,Two Pointers,Greedy,1+
  32. 3Sum With Multiplicity-Array,Hash Table,Two Pointers,2+
  33. Bag of Tokens-Array,Two Pointers,Greedy,1+
  34. Pancake Sorting-Array,Two Pointers,Greedy,1+
  35. Interval List Intersections-Array,Two Pointers
  36. Moving Stones Until Consecutive II-Array,Math,Two Pointers,1+
  37. Longest String Chain-Array,Hash Table,Two Pointers,2+
  38. Meeting Scheduler-Array,Two Pointers,Sorting
  39. The k Strongest Values in an Array-Array,Two Pointers,Sorting
  40. Number of Subsequences That Satisfy the Given Sum Condition-Array,Two Pointers,Binary Search,1+
  41. Range Sum of Sorted Subarray Sums-Array,Two Pointers,Binary Search,1+
  42. Dot Product of Two Sparse Vectors-Array,Hash Table,Two Pointers,1+
  43. Shortest Subarray to be Removed to Make Array Sorted-Array,Two Pointers,Binary Search,2+
  44. Number of Ways Where Square of Number Is Equal to Product of Two Numbers-Array,Hash Table,Math,1+
  45. Max Number of K-Sum Pairs-Array,Hash Table,Two Pointers,1+
  46. Ways to Split Array Into Three Subarrays-Array,Two Pointers,Binary Search,1+
  47. Sentence Similarity III-Array,Two Pointers,String
  48. Maximum Distance Between a Pair of Values-Array,Two Pointers,Binary Search,1+
  49. Rotating the Box-Array,Two Pointers,Matrix
  50. Product of Two Run-Length Encoded Arrays-Array,Two Pointers
  51. Minimize Maximum Pair Sum in Array-Array,Two Pointers,Greedy,1+
  52. Watering Plants II-Array,Two Pointers,Simulation
  53. Rearrange Array Elements by Sign-Array,Two Pointers,Simulation
  54. Partition Array According to Given Pivot-Array,Two Pointers,Simulation
  55. Successful Pairs of Spells and Potions-Array,Two Pointers,Binary Search,1+
  56. The Latest Time to Catch a Bus-Array,Two Pointers,Binary Search,1+
  57. Divide Intervals Into Minimum Number of Groups-Array,Two Pointers,Greedy,3+
  58. Maximum Matching of Players With Trainers-Array,Two Pointers,Greedy,1+
  59. Merge Operations to Turn Array Into a Palindrome-Array,Two Pointers,Greedy
  60. Total Cost to Hire K Workers-Array,Two Pointers,2+
  61. Divide Players Into Teams of Equal Skill-Array,Hash Table,Two Pointers,1+
  62. Count the Number of Fair Pairs-Array,Two Pointers,Binary Search,1+
  63. Find the Maximum Number of Marked Indices-Array,Two Pointers,Binary Search,2+
  64. Maximize Greatness of an Array-Array,Two Pointers,Greedy,1+

(Sliding Window)

  1. Minimum Size Subarray Sum-Array,Binary Search,Sliding Window,1+
  2. Max Consecutive Ones II-Array,Dynamic Programming,Sliding Window
  3. Find K Closest Elements-Array,Two Pointers,Binary Search,3+
  4. Subarray Product Less Than K-Array,Sliding Window
  5. Maximum Length of Repeated Subarray-Array,Binary Search,4+
  6. Fruit Into Baskets-Array,Hash Table,Sliding Window
  7. Binary Subarrays With Sum-Array,Hash Table,Sliding Window,1+
  8. Longest Turbulent Subarray-Array,Dynamic Programming,Sliding Window
  9. Max Consecutive Ones III-Array,Binary Search,Sliding Window,1+
  10. Maximum Sum of Two Non-Overlapping Subarrays-Array,Dynamic Programming,Sliding Window
  11. Grumpy Bookstore Owner-Array,Sliding Window
  12. Minimum Swaps to Group All 1's Together-Array,Sliding Window
  13. Count Number of Nice Subarrays-Array,Hash Table,Math,1+
  14. Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold-Array,Sliding Window
  15. Maximum Points You Can Obtain from Cards-Array,Sliding Window,Prefix Sum
  16. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit-Array,Queue,Sliding Window,3+
  17. Find Two Non-overlapping Sub-arrays Each With Target Sum-Array,Hash Table,Binary Search,2+
  18. Longest Subarray of 1's After Deleting One Element-Array,Dynamic Programming,Sliding Window
  19. Minimum Operations to Reduce X to Zero-Array,Hash Table,Binary Search,2+
  20. Maximum Erasure Value-Array,Hash Table,Sliding Window
  21. Jump Game VI-Array,Dynamic Programming,Queue,3+
  22. Frequency of the Most Frequent Element-Array,Binary Search,Greedy,3+
  23. Distinct Numbers in Each Subarray-Array,Hash Table,Sliding Window
  24. Kth Smallest Subarray Sum-Array,Binary Search,Sliding Window
  25. K Radius Subarray Averages-Array,Sliding Window
  26. Number of Unique Flavors After Sharing K Candies-Array,Hash Table,Sliding Window
  27. Minimum Swaps to Group All 1's Together II-Array,Sliding Window
  28. Minimum Consecutive Cards to Pick Up-Array,Hash Table,Sliding Window
  29. Longest Nice Subarray-Array,Bit Manipulation,Sliding Window
  30. Smallest Subarrays With Maximum Bitwise OR-Array,Binary Search,Bit Manipulation,1+
  31. Maximum Sum of Distinct Subarrays With Length K-Array,Hash Table,Sliding Window
  32. Count the Number of Good Subarrays-Array,Hash Table,Sliding Window
  33. Maximize Win From Two Segments-Array,Binary Search,Sliding Window
  34. Sliding Subarray Beauty-Array,Hash Table,Sliding Window

3.Array - Hard level (Two Pointer)

  1. Trapping Rain Water-Array,Two Pointers,3+
  2. Find K-th Smallest Pair Distance-Array,Two Pointers,Binary Search,1+
  3. Get the Maximum Score-Array,Two Pointers,2+
  4. Closest Subsequence Sum,Array,Two Pointers,3+
  5. Maximum Score of a Good Subarray-Array,Two Pointers,Binary Search,2+
  6. Partition Array Into Two Arrays to Minimize Sum Difference-Array,Two Pointers,Binary Search,4+
  7. Maximum Total Beauty of the Gardens-Array,Two Pointers,Binary Search,2+

(Sliding Window)

  1. Contains Duplicate III-Array,Sliding Window,Sorting,2+
  2. Sliding Window Maximum-Array,Queue,Sliding Window,2+
  3. Sliding Window Median-Array,Hash Table,Sliding Window,1+
  4. Smallest Range Covering Elements from K Lists-Array,Hash Table,Greedy,3+
  5. K Empty Slots-Array,Binary Indexed Tree,2+
  6. Shortest Subarray with Sum at Least K-Array,Binary Search,Queue,4+
  7. Subarrays with K Different Integers-Array,Hash Table,Sliding Window,1+
  8. Minimum Number of K Consecutive Bit Flips-Array,Bit Manipulation,Queue,2+
  9. Constrained Subsequence Sum-Array,Dynamic Programming,Queue,3+
  10. Max Value of Equation-Array,Queue,Sliding Window,2+
  11. Maximum Number of Visible Points-Array,Math,Geometry,2+
  12. Minimum Adjacent Swaps for K Consecutive Ones-Array,Greedy,Sliding Window,1+
  13. Maximum Fruits Harvested After at Most K Steps-Array,Binary Search,Sliding Window,1+
  14. Count Subarrays With Score Less Than K-Array,Binary Search,Sliding Window,1+
  15. Maximum Number of Robots Within Budget-Array,Binary Search,Queue,3+
  16. Count Subarrays With Fixed Bounds-Array,Queue,Sliding Window,1+
  17. Maximum Frequency Score of a Subarray-Array,Hash Table,Math,1+
  18. 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/

About

Collection of LeetCode questions to ace the coding interview! - Created using [LeetHub](https://github.com/QasimWani/LeetHub)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published