LeetCode Questions For MAANG
LeetCode Questions For MAANG
MAANG/FAANG
Topics-array, matrix,string,searching and sorting,linkedlist,binary trees,
binary searched tree,greedy, backtracking,stacks,queues,heap,graph,trie,
dynamic programming,bit manipulation
Let's begin:
Arrays
**Easy:**
1. Two Sum (#1)
2. Best Time to Buy and Sell Stock (#121)
3. Contains Duplicate (#217)
4. Maximum Subarray (#53)
5. Move Zeroes (#283)
6. Rotate Array (#189)
7. Intersection of Two Arrays II (#350)
8. Plus One (#66)
9. Remove Duplicates from Sorted Array (#26)
10. Missing Number (#268)
**Medium:**
11. 3Sum (#15)
12. Set Matrix Zeroes (#73)
13. Product of Array Except Self (#238)
14. Subarray Sum Equals K (#560)
15. Next Permutation (#31)
16. Longest Consecutive Sequence (#128)
17. Search in Rotated Sorted Array (#33)
18. Jump Game (#55)
19. Spiral Matrix (#54)
20. Merge Intervals (#56)
**Hard:**
21. Trapping Rain Water (#42)
22. Largest Rectangle in Histogram (#84)
23. Median of Two Sorted Arrays (#4)
24. First Missing Positive (#41)
25. Maximum Gap (#164)
26. Candy (#135)
27. Sliding Window Maximum (#239)
28. Merge k Sorted Lists (#23)
29. Create Maximum Number (#321)
30. Nth Magical Number (#878)
Matrices
**Easy:**
1. Reshape the Matrix (#566)
2. Diagonal Traverse (#498)
3. Toeplitz Matrix (#766)
4. Transpose Matrix (#867)
5. Flipping an Image (#832)
6. Matrix Cells in Distance Order (#1030)
7. Matrix Diagonal Sum (#1572)
8. Lucky Numbers in a Matrix (#1380)
**Medium:**
9. Set Matrix Zeroes (#73)
10. Rotate Image (#48)
11. Word Search (#79)
12. Spiral Matrix (#54)
13. Search a 2D Matrix (#74)
14. Maximal Square (#221)
15. Number of Islands (#200)
16. Surrounded Regions (#130)
17. Pacific Atlantic Water Flow (#417)
18. Path with Minimum Effort (#1631)
**Hard:**
19. Maximal Rectangle (#85)
20. Dungeon Game (#174)
21. Count of Smaller Numbers After Self (#315)
22. Best Meeting Point (#296)
23. Find the Kth Smallest Sum of a Matrix With Sorted Rows (#1439)
24. Paint House II (#265)
Strings
**Easy:**
1. Valid Palindrome (#125)
2. Longest Common Prefix (#14)
3. Implement strStr() (#28)
4. Reverse String (#344)
5. Reverse Words in a String III (#557)
6. First Unique Character in a String (#387)
7. Ransom Note (#383)
8. Valid Anagram (#242)
9. Palindrome Permutation (#266)
10. Excel Sheet Column Title (#168)
**Medium:**
11. Longest Substring Without Repeating Characters (#3)
12. Longest Palindromic Substring (#5)
13. String to Integer (atoi) (#8)
14. Group Anagrams (#49)
15. Letter Combinations of a Phone Number (#17)
16. Valid Parentheses (#20)
17. Decode Ways (#91)
18. Count and Say (#38)
19. Longest Repeating Character Replacement (#424)
20. Minimum Window Substring (#76)
**Hard:**
21. Wildcard Matching (#44)
22. Regular Expression Matching (#10)
23. Edit Distance (#72)
24. Scramble String (#87)
25. Word Ladder II (#126)
26. Word Search II (#212)
27. Basic Calculator (#224)
28. Remove Invalid Parentheses (#301)
29. Longest Valid Parentheses (#32)
30. Distinct Subsequences (#115):
**Medium:**
1. Search for a Range (#34)
2. Find Peak Element (#162)
3. Search a 2D Matrix II (#240)
4. Kth Largest Element in an Array (#215)
5. Find the Duplicate Number (#287)
6. Sort Colors (#75)
7. Search in Rotated Sorted Array (#33)
8. Top K Frequent Elements (#347)
9. Sort List (#148)
10. Wiggle Sort II (#324)
**Hard:**
1. Median of Two Sorted Arrays (#4)
2. Merge k Sorted Lists (#23)
3. Find Minimum in Rotated Sorted Array II (#154)
4. First Missing Positive (#41)
5. Merge Intervals (#56)
6. Maximum Gap (#164)
7. Trapping Rain Water (#42)
8. Count of Smaller Numbers After Self (#315)
9. Minimum Window Substring (#76)
10. Russian Doll Envelopes (#354)
Linked List
**Easy:**
1. Reverse Linked List (#206)
2. Merge Two Sorted Lists (#21)
3. Remove Nth Node From End of List (#19)
4. Linked List Cycle (#141)
5. Palindrome Linked List (#234)
6. Delete Node in a Linked List (#237)
7. Intersection of Two Linked Lists (#160)
8. Remove Linked List Elements (#203)
9. Design Linked List (#707)
10. Convert Binary Number in a Linked List to Integer (#1290)
**Medium:**
1. Add Two Numbers (#2)
2. Odd Even Linked List (#328)
3. Reverse Linked List II (#92)
4. Copy List with Random Pointer (#138)
5. Reorder List (#143)
6. Remove Duplicates from Sorted List II (#82)
7. Rotate List (#61)
8. Split Linked List in Parts (#725)
9. Sort List (#148)
10. Swap Nodes in Pairs (#24)
**Hard:**
1. Merge k Sorted Lists (#23)
2. Reverse Nodes in k-Group (#25)
3. Palindrome Partitioning (#131)
4. Copy List with Random Pointer (#138)
5. Linked List Cycle II (#142)
6. LFU Cache (#460)
7. LRU Cache (#146)
8. Remove Zero Sum Consecutive Nodes from Linked List (#1171)
9. Insert into a Cyclic Sorted List (#708)
10. Flatten a Multilevel Doubly Linked List (#430)
Binary Trees
**Easy:**
1. Maximum Depth of Binary Tree (#104)
2. Same Tree (#100)
3. Invert Binary Tree (#226)
4. Binary Tree Level Order Traversal (#102)
5. Symmetric Tree (#101)
6. Path Sum (#112)
7. Convert Sorted Array to Binary Search Tree (#108)
8. Balanced Binary Tree (#110)
9. Minimum Depth of Binary Tree (#111)
10. Diameter of Binary Tree (#543)
**Medium:**
1. Binary Tree Zigzag Level Order Traversal (#103)
2. Construct Binary Tree from Preorder and Inorder Traversal (#105)
3. Flatten Binary Tree to Linked List (#114)
4. Binary Tree Right Side View (#199)
5. Path Sum II (#113)
6. Lowest Common Ancestor of a Binary Tree (#236)
7. Binary Tree Level Order Traversal II (#107)
8. Kth Smallest Element in a BST (#230)
9. Count Complete Tree Nodes (#222)
10. Validate Binary Search Tree (#98)
**Hard:**
1. Serialize and Deserialize Binary Tree (#297)
2. Binary Tree Maximum Path Sum (#124)
3. Recover Binary Search Tree (#99)
4. Longest Consecutive Sequence (#298)
5. Vertical Order Traversal of a Binary Tree (#987)
6. Binary Tree Cameras (#968)
7. Maximum Sum BST in Binary Tree (#1373)
8. Smallest Subtree with all the Deepest Nodes (#865)
9. Binary Tree Coloring Game (#1145)
10. All Nodes Distance K in Binary Tree (#863)
**Medium:**
1. Kth Smallest Element in a BST (#230)
2. Delete Node in a BST (#450)
3. Lowest Common Ancestor of a Binary Tree (#236)
4. Binary Search Tree Iterator (#173)
5. Find Mode in Binary Search Tree (#501)
6. Construct Binary Search Tree from Preorder Traversal (#1008)
7. Convert Binary Search Tree to Sorted Doubly Linked List (#426)
8. Validate Binary Search Tree (#98)
9. Insert into a Binary Search Tree (#701)
10. Inorder Successor in BST II (#510)
**Hard:**
1. Recover Binary Search Tree (#99)
2. Serialize and Deserialize BST (#449)
3. Maximum Sum BST in Binary Tree (#1373)
4. Smallest Subtree with all the Deepest Nodes (#865)
5. Binary Tree Cameras (#968)
6. Closest Binary Search Tree Value II (#272)
7. Count of Smaller Numbers After Self (#315)
8. Range Sum of BST (#938)
9. Construct Binary Search Tree from Preorder Traversal (#1008)
10. Validate Binary Search Tree (#98)
Greedy
**Easy:**
1. Assign Cookies (#455)
2. Best Time to Buy and Sell Stock (#121)
3. Lemonade Change (#860)
4. Non-decreasing Array (#665)
5. Greatest Sum Divisible by Three (#1262)
6. Can Place Flowers (#605)
7. Meeting Rooms (#252)
8. Boats to Save People (#881)
9. Gas Station (#134)
10. Walking Robot Simulation (#874)
**Medium:**
1. Jump Game (#55)
2. Partition Labels (#763)
3. Gas Station (#134)
4. Task Scheduler (#621)
5. Minimum Number of Arrows to Burst Balloons (#452)
6. Jump Game II (#45)
7. Hand of Straights (#846)
8. Car Fleet (#853)
9. Bag of Tokens (#948)
10. Coin Change (#322)
**Hard:**
1. Trapping Rain Water (#42)
2. Candy (#135)
3. Jump Game II (#45)
4. Split Array Largest Sum (#410)
5. Minimum Cost to Merge Stones (#1000)
6. Minimum Window Substring (#76)
7. Create Maximum Number (#321)
8. Shortest Subarray with Sum at Least K (#862)
9. Minimum Number of Refueling Stops (#871)
10. Russian Doll Envelopes (#354)
Backtracking
**Easy:**
1. Letter Combinations of a Phone Number (#17)
2. Generate Parentheses (#22)
3. Permutations (#46)
4. Subsets (#78)
5. Combination Sum (#39)
6. Palindrome Partitioning (#131)
7. Word Search (#79)
8. Permutations II (#47)
9. Combinations (#77)
10. Subsets II (#90)
**Medium:**
1. Word Search (#79)
2. Palindrome Partitioning (#131)
3. Combinations (#77)
4. Combination Sum II (#40)
5. Permutations II (#47)
6. N-Queens (#51)
7. Sudoku Solver (#37)
8. Word Search II (#212)
9. Regular Expression Matching (#10)
10. Wildcard Matching (#44)
**Hard:**
1. N-Queens (#51)
2. Sudoku Solver (#37)
3. Word Search II (#212)
4. Regular Expression Matching (#10)
5. Wildcard Matching (#44)
6. N-Queens II (#52)
7. Palindrome Partitioning II (#132)
8. Word Break II (#140)
9. Restore IP Addresses (#93)
10. Concatenated Words (#472)
Stacks
**Easy:**
1. Valid Parentheses (#20)
2. Min Stack (#155)
3. Implement Queue using Stacks (#232)
4. Remove Outermost Parentheses (#1021)
5. Baseball Game (#682)
6. Next Greater Element I (#496)
7. Daily Temperatures (#739)
8. Asteroid Collision (#735)
9. Largest Rectangle in Histogram (#84)
10. Evaluate Reverse Polish Notation (#150)
**Medium:**
1. Evaluate Reverse Polish Notation (#150)
2. Decode String (#394)
3. Next Greater Element I (#496)
4. Daily Temperatures (#739)
5. Asteroid Collision (#735)
6. Trapping Rain Water (#42)
7. Largest Rectangle in Histogram (#84)
8. Basic Calculator (#224)
9. Basic Calculator II (#227)
10. Remove Invalid Parentheses (#
301)
**Hard:**
1. Trapping Rain Water (#42)
2. Largest Rectangle in Histogram (#84)
3. Basic Calculator (#224)
4. Basic Calculator II (#227)
5. Remove Invalid Parentheses (#301)
6. Minimum Remove to Make Valid Parentheses (#1249)
7. Maximal Rectangle (#85)
8. Evaluate Reverse Polish Notation (#150)
9. Sliding Window Maximum (#239)
10. Parsing A Boolean Expression (#1106)
Queues
**Easy:**
1. Implement Queue using Stacks (#232)
2. Design Circular Queue (#622)
3. Design Hit Counter (#362)
4. Number of Recent Calls (#933)
5. Perfect Squares (#279)
6. Rotting Oranges (#994)
7. Walls and Gates (#286)
8. Open the Lock (#752)
9. Design Snake Game (#353)
10. Design Circular Deque (#641)
**Medium:**
1. Walls and Gates (#286)
2. Open the Lock (#752)
3. Design Snake Game (#353)
4. Design Circular Deque (#641)
5. Sliding Window Maximum (#239)
6. Cut Off Trees for Golf Event (#675)
7. Trapping Rain Water II (#407)
8. Shortest Path to Get All Keys (#864)
9. Bus Routes (#815)
10. Alien Dictionary (#269)
**Hard:**
1. Cut Off Trees for Golf Event (#675)
2. Trapping Rain Water II (#407)
3. Shortest Path to Get All Keys (#864)
4. Bus Routes (#815)
5. Alien Dictionary (#269)
6. Race Car (#818)
7. Reachable Nodes In Subdivided Graph (#882)
8. Escape a Large Maze (#1036)
9. Minimum Number of Refueling Stops (#871)
10. Minimum Window Substring (#76)
Heap
**Easy:**
1. Last Stone Weight (#1046)
2. Kth Largest Element in a Stream (#703)
3. Top K Frequent Elements (#347)
4. K Closest Points to Origin (#973)
5. Find Median from Data Stream (#295)
6. Task Scheduler (#621)
7. Reorganize String (#767)
8. Merge k Sorted Lists (#23)
9. Sort Characters By Frequency (#451)
10. Find Median from Data Stream (#295)
**Medium:**
1. Task Scheduler (#621)
2. Reorganize String (#767)
3. Merge k Sorted Lists (#23)
4. Sort Characters By Frequency (#451)
5. Find Median from Data Stream (#295)
6. Top K Frequent Words (#692)
7. Furthest Building You Can Reach (#1642)
8. Kth Smallest Element in a Sorted Matrix (#378)
9. Find K Pairs with Smallest Sums (#373)
10. Sliding Window Maximum (#239)
**Hard:**
1. Trapping Rain Water II (#407)
2. Merge k Sorted Lists (#23)
3. Find Median from Data Stream (#295)
4. Sliding Window Maximum (#239)
5. Kth Smallest Element in a Sorted Matrix (#378)
6. Top K Frequent Words (#692)
7. Furthest Building You Can Reach (#1642)
8. Kth Smallest Element in a Sorted Matrix (#378)
9. Find K Pairs with Smallest Sums (#373)
10. Sliding Window Maximum (#239)
Graphs
**Easy:**
1. Find the Town Judge (#997)
2. Find if Path Exists in Graph (#1971)
3. All Paths From Source to Target (#797)
4. Course Schedule (#207)
5. Clone Graph (#133)
6. Number of Islands (#200)
7. Course Schedule II (#210)
8. Redundant Connection (#684)
9. Graph Valid Tree (#261)
10. Minimum Height Trees (#310)
**Medium:**
1. Number of Connected Components in an Undirected Graph (#323)
2. Course Schedule II (#210)
3. Redundant Connection (#684)
4. Graph Valid Tree (#261)
5. Minimum Height Trees (#310)
6. Word Ladder (#127)
7. Minimum Cost to Make at Least One Valid Path in a Grid (#1368)
8. Critical Connections in a Network (#1192)
9. Alien Dictionary (#269)
10. Longest Increasing Path in a Matrix (#329)
**Hard:**
1. Word Ladder II (#126)
2. Minimum Cost to Make at Least One Valid Path in a Grid (#1368)
3. Critical Connections in a Network (#1192)
4. Alien Dictionary (#269)
5. Longest Increasing Path in a Matrix (#329)
6. Word Ladder II (#126)
7. Minimum Cost to Make at Least One Valid Path in a Grid (#1368)
8. Critical Connections in a Network (#1192)
9. Alien Dictionary (#269)
10. Longest Increasing Path in a Matrix (#329)
Tries
**Easy:**
1. Implement Trie (Prefix Tree) (#208)
2. Add and Search Word - Data structure design (#211)
3. Replace Words (#648)
4. Word Search II (#212)
5. Implement Trie II (Prefix Tree) (#1804)
6. Maximum XOR of Two Numbers in an Array (#421)
7. Design Add and Search Words Data Structure (#211)
8. Map Sum Pairs (#677)
9. Concatenated Words (#472)
10. Design Search Autocomplete System (#642)
**Medium:**
1. Word Search II (#212)
2. Design Add and Search Words Data Structure (#211)
3. Map Sum Pairs (#677)
4. Concatenated Words (#472)
5. Design Search Autocomplete System (#642)
6. Implement Trie II (Prefix Tree) (#1804)
7. Maximum XOR of Two Numbers in an Array (#421)
8. Replace Words (#648)
9. Add and Search Word - Data structure design (#211)
10. Word Search II (#212)
**Hard:**
1. Word Search II (#212)
2. Concatenated Words (#472)
3. Design Search Autocomplete System (#642)
4. Replace Words (#648)
5. Add and Search Word - Data structure design (#211)
6. Implement Trie II (Prefix Tree) (#1804)
7. Maximum XOR of Two Numbers in an Array (#421)
8. Map Sum Pairs (#677)
9. Concatenated Words (#472)
10. Design Search Autocomplete System (#642)
Dynamic Programming
**Easy:**
1. Climbing Stairs (#70)
2. Best Time to Buy and Sell Stock (#121)
3. House Robber (#198)
4. Maximum Subarray (#53)
5. Coin Change (#322)
6. Longest Increasing Subsequence (#300)
7. Unique Paths (#62)
8. Decode Ways (#91)
9. Jump Game (#55)
10. Minimum Path Sum (#64)
**Medium:**
1. Longest Palindromic Substring (#5)
2. Palindromic Substrings (#647)
3. Longest Common Subsequence (#1143)
4. Edit Distance (#72)
5. Interleaving String (#97)
6. Coin Change (#322)
7. Longest Increasing Subsequence (#300)
8. Unique Paths (#62)
9. Decode Ways (#91)
10. Jump Game (#55)
**Hard:**
1. Word Break II (#140)
2. Burst Balloons (#312)
3. Dungeon Game (#174)
4. Russian Doll Envelopes (#354)
5. Minimum Window Substring (#76)
6. Trapping Rain Water (#42)
7. Edit Distance (#72)
8. Regular Expression Matching (#10)
9. Wildcard Matching (#44)
10. Palindrome Partitioning II (#132)
Bit Manipulation
**Easy:**
1. Single Number (#136)
2. Number of 1 Bits (#191)
3. Reverse Bits (#190)
4. Power of Two (#231)
5. Hamming Distance (#461)
6. Counting Bits (#338)
7. Missing Number (#268)
8. Sum of Two Integers (#371)
9. Complement of Base 10 Integer (#1009)
10. XOR Operation in an Array (#1486)
**Medium:**
1. Single Number II (#137)
2. Subsets (#78)
3. Counting Bits (#338)
4. Total Hamming Distance (#477)
5. Bitwise AND of Numbers Range (#201)
6. Single Number III (#260)
7. Maximum Product of Word Lengths (#318)
8. Divide Two Integers (#29)
9. Sum of Two Integers (#371)
10. Find the Duplicate Number (#287)
**Hard:**
1. Maximum XOR of Two Numbers in an Array (#421)
2. Binary Tree Maximum Path Sum (#124)
3. Number of Valid Words for Each Puzzle (#1178)
4. Minimum XOR Sum of Two Arrays (#1879)
5. Bitwise ORs of Subarrays (#898)
6. Count Different Palindromic Subsequences (#730)
7. Palindrome Partitioning III (#1278)
8. Minimum Cost to Merge Stones (#1000)
9. Concatenated Words (#472)
10. Maximum Sum of 3 Non-Overlapping Subarrays (#689)