Skip to content

This repository contains solutions to LeetCode Top 150 Interview Problems. Must-do List for Interview Prep 🎯

License

Notifications You must be signed in to change notification settings

ChunhThanhDe/Leetcode-Top-Interview

Repository files navigation

Leetcode Top Interview 🎯

This repository contains solutions to the Leetcode Top Interview 150 problems.

These problems are commonly asked in technical interviews and cover a wide range of topics, including data structures, algorithms, and problem-solving techniques.

Leetcode Stats

Show some ❀️ by starring ⭐ this repository if you like it!

Contact for work, email: [email protected]

LeetCode Logo

GitHub stars GitHub forks GitHub watchers

linkedin

Buy Me A Coffee

Table of Contents πŸ“–

What is Leetcode? πŸ§‘β€πŸ’»

Leetcode is a popular online platform that provides a collection of coding challenges. Software engineers and interview candidates widely use it to practice coding skills and prepare for technical interviews. Leetcode offers many problems to solve, classified by difficulty level and topic.

About the Top Interview 150 Collection πŸ†

The Top Interview 150 collection on Leetcode is a curated set of 150 interview questions that top tech companies frequently ask. These questions are carefully selected to cover essential concepts and algorithms that interviewers expect candidates to be familiar with.

Id Problem Difficulty Signal Status
Array / String
1 Merge Sorted Array Easy 🟒 βœ…
2 Remove Element Easy 🟒 βœ…
3 Remove Duplicates from Sorted Array Easy 🟒 βœ…
4 Remove Duplicates from Sorted Array II Medium 🟑 βœ…
5 Majority Element Easy 🟒 βœ…
6 Rotate Array Medium 🟑 βœ…
7 Best Time to Buy and Sell Stock Easy 🟒 βœ…
8 Best Time to Buy and Sell Stock II Medium 🟑 βœ…
9 Jump Game Medium 🟑 βœ…
10 Jump Game II Medium 🟑 βœ…
11 H-Index Medium 🟑 βœ…
12 Insert Delete GetRandom O(1) Medium 🟑 βœ…
13 Product of Array Except Self Medium 🟑 βœ…
14 Gas Station Medium 🟑 βœ…
15 Candy Hard πŸ”΄ βœ…
16 Trapping Rain Water Hard πŸ”΄ βœ…
17 Roman to Integer Easy 🟒 βœ…
18 Integer to Roman Medium 🟑 βœ…
19 Length of Last Word Easy 🟒 βœ…
20 Longest Common Prefix Easy 🟒 βœ…
21 Reverse Words in a String Medium 🟑 βœ…
22 Zigzag Conversion Medium 🟑 βœ…
23 Find the Index of the First Occurrence in a String Easy 🟒 βœ…
24 Text Justification Hard πŸ”΄ βœ…
Two Pointers
25 Valid Palindrome Easy 🟒 βœ…
26 Is Subsequence Easy 🟒 βœ…
27 Two Sum II - Input Array Is Sorted Medium 🟑 βœ…
28 Container With Most Water Medium 🟑 βœ…
29 3Sum Medium 🟑 βœ…
Sliding Window
30 Minimum Size Subarray Sum Medium 🟑 βœ…
31 Longest Substring Without Repeating Characters Medium 🟑 βœ…
32 Substring with Concatenation of All Words Hard πŸ”΄ βœ…
33 Minimum Window Substring Hard πŸ”΄ βœ…
Matrix
34 Valid Sudoku Medium 🟑 βœ…
35 Spiral Matrix Medium 🟑 βœ…
36 Rotate Image Medium 🟑 βœ…
37 Set Matrix Zeroes Medium 🟑 βœ…
38 Game of Life Medium 🟑 βœ…
Hashmap
39 Ransom Note Easy 🟒 βœ…
40 Isomorphic Strings Easy 🟒 βœ…
41 Word Pattern Easy 🟒 βœ…
42 Valid Anagram Easy 🟒 βœ…
43 Group Anagrams Medium 🟑 βœ…
44 Two Sum Easy 🟒 βœ…
45 Happy Number Easy 🟒 βœ…
46 Contains Duplicate II Easy 🟒 βœ…
47 Longest Consecutive Sequence Medium 🟑 βœ…
Intervals
48 Summary Ranges Easy 🟒 βœ…
49 Merge Intervals Medium 🟑 βœ…
50 Insert Interval Medium 🟑 βœ…
51 Minimum Number of Arrows to Burst Balloons Medium 🟑 βœ…
Stack
52 Valid Parentheses Easy 🟒 βœ…
53 Simplify Path Medium 🟑 βœ…
54 Min Stack Medium 🟑 βœ…
55 Evaluate Reverse Polish Notation Medium 🟑 βœ…
56 Basic Calculator Hard πŸ”΄ βœ…
Linked List
57 Linked List Cycle Easy 🟒 βœ…
58 Add Two Numbers Medium 🟑 βœ…
59 Merge Two Sorted Lists Easy 🟒 βœ…
60 Copy List with Random Pointer Medium 🟑 βœ…
61 Reverse Linked List II Medium 🟑 βœ…
62 Reverse Nodes in k-Group Hard πŸ”΄ βœ…
63 Remove Nth Node From End of List Medium 🟑 βœ…
64 Remove Duplicates from Sorted List II Medium 🟑 βœ…
65 Rotate List Medium 🟑 βœ…
66 Partition List Medium 🟑 βœ…
67 LRU Cache Medium 🟑 βœ…
Binary Tree General
68 Maximum Depth of Binary Tree Easy 🟒 βœ…
69 Same Tree Easy 🟒 βœ…
70 Invert Binary Tree Easy 🟒 βœ…
71 Symmetric Tree Easy 🟒 βœ…
72 Construct Binary Tree from Preorder and Inorder Traversal Medium 🟑 βœ…
73 Construct Binary Tree from Inorder and Postorder Traversal Medium 🟑 βœ…
74 Populating Next Right Pointers in Each Node II Medium 🟑 βœ…
75 Flatten Binary Tree to Linked List Medium 🟑
76 Path Sum Easy 🟒
77 Sum Root to Leaf Numbers Medium 🟑
78 Binary Tree Maximum Path Sum Hard πŸ”΄
79 Binary Search Tree Iterator Medium 🟑
80 Count Complete Tree Nodes Easy 🟒
81 Lowest Common Ancestor of a Binary Tree Medium 🟑
Binary Tree BFS
8282 Binary Tree Right Side View Medium 🟑
83 Average of Levels in Binary Tree Easy 🟒
84 Binary Tree Level Order Traversal Medium 🟑
85 Binary Tree Zigzag Level Order Traversal Medium 🟑
Binary Search Tree
86 Minimum Absolute Difference in BST Easy 🟒
87 Kth Smallest Element in a BST Medium 🟑
88 Validate Binary Search Tree Medium 🟑
Graph General
89 Number of Islands Medium 🟑
90 Surrounded Regions Medium 🟑
91 Clone Graph Medium 🟑
92 Evaluate Division Medium 🟑
93 Course Schedule Medium 🟑
94 Course Schedule II Medium 🟑
Graph BFS
95 Snakes and Ladders Medium 🟑
96 Minimum Genetic Mutation Medium 🟑
97 Word Ladder Hard πŸ”΄
Trie
98 Implement Trie (Prefix Tree) Medium 🟑
99 Design Add and Search Words Data Structure Medium 🟑
100 Word Search II Hard πŸ”΄
Backtracking
101 Letter Combinations of a Phone Number Medium 🟑
102 Combinations Medium 🟑
103 Permutations Medium 🟑
104 Combination Sum Medium 🟑
105 N-Queens II Hard πŸ”΄
106 Generate Parentheses Medium 🟑
107 Word Search Medium 🟑
Divide & Conquer
108 Convert Sorted Array to Binary Search Tree Easy 🟒
109 Sort List Medium 🟑
110 Construct Quad Tree Medium 🟑
111 Merge k Sorted Lists Hard πŸ”΄
Kadane's Algorithm
112 Maximum Subarray Medium 🟑
113 Maximum Sum Circular Subarray Medium 🟑
Binary Search
114 Search Insert Position Easy 🟒
115 Search a 2D Matrix Medium 🟑
116 Find Peak Element Medium 🟑
117 Search in Rotated Sorted Array Medium 🟑
118 Find First and Last Position of Element in Sorted Array Medium 🟑
119 Find Minimum in Rotated Sorted Array Medium 🟑
120 Median of Two Sorted Arrays Hard πŸ”΄
Heap
121 Kth Largest Element in an Array Medium 🟑
122 IPO Hard πŸ”΄
123 Find K Pairs with Smallest Sums Medium 🟑
124 Find Median from Data Stream Hard πŸ”΄
Bit Manipulation
125 Add Binary Easy 🟒
126 Reverse Bits Easy 🟒
127 Number of 1 Bits Easy 🟒
128 Single Number Easy 🟒
129 Single Number II Medium 🟑
130 Bitwise AND of Numbers Range Medium 🟑
Math
131 Palindrome Number Easy 🟒
132 Plus One Easy 🟒
133 Factorial Trailing Zeroes Medium 🟑
134 Sqrt(x) Easy 🟒
135 Pow(x, n) Medium 🟑
136 Max Points on a Line Hard πŸ”΄
1D DP
137 Climbing Stairs Easy 🟒
138 House Robber Medium 🟑
139 Word Break Medium 🟑
140 Coin Change Medium 🟑
141 Longest Increasing Subsequence Medium 🟑
Multidimensional DP
142 Triangle Medium 🟑
143 Minimum Path Sum Medium 🟑
144 Unique Paths II Medium 🟑
145 Longest Palindromic Substring Medium 🟑
146 Interleaving String Medium 🟑
147 Edit Distance Medium 🟑
148 Best Time to Buy and Sell Stock III Hard πŸ”΄
149 Best Time to Buy and Sell Stock IV Hard πŸ”΄
150 Maximal Square Medium 🟑

Tips for Solving Problems πŸ’‘

SSome helpful strategies to tackle different types of problems in this repository:

Strategy Description Example Use Case
Heap for Top K Elements πŸ”Ό Use a Heap to find the top K largest, smallest, or closest elements among N elements. Efficient for problems requiring constant updates. Finding the top K largest numbers in a list.
Binary Search or Two Pointers for Sorted Input πŸ”βž‘οΈβ¬…οΈ Use Binary Search or Two Pointers for sorted arrays, lists, or matrices to optimize the solution. Searching for an element in a sorted array.
Backtracking or BFS for Combinations and Permutations πŸ”„πŸ” Use Backtracking or BFS for problems requiring exploration of all combinations or permutations. Finding all permutations of a set.
BFS or DFS for Trees and Graphs πŸŒ³πŸ”— Use BFS or DFS for tree or graph-related problems. Searching a graph or binary tree.
Stack for Converting Recursion to Iteration πŸ“š Convert recursion problems into iterative solutions using a stack to simulate the call stack. Performing a recursive search without using recursion.
Optimizing Array Problems πŸ“Š Optimize array problems from O(nΒ²) to O(n) using a HashMap or Set, or to O(n log n) using sorting. Finding duplicate elements in an array.
Dynamic Programming for Optimization Problems πŸš€ Dynamic Programming is essential for problems that involve maximizing or minimizing values, using results from previous subproblems. Finding the maximum value in a sequence.
Trie for String Manipulation πŸ”€ For multiple strings or searching for common substrings, use a Trie or HashMap. A Trie is the most suitable data structure when manipulating multiple strings. Searching or manipulating multiple strings efficiently.
Fast & Slow Pointers for Linked Lists πŸ”„πŸƒβ€β™‚οΈπŸƒβ€β™€οΈ Use Fast & Slow Pointers to efficiently solve LinkedList problems with restricted memory usage, like detecting cycles or finding the middle element. Detecting cycles or finding the middle of a linked list.

Repository Structure πŸ—‚οΈ

This repository is organized by problem number, with each problem having its own directory.

Inside each problem directory, you will find the solution file(s) along with a README file that provides a problem description, constraints, and additional notes if necessary.

How to Use This Repository πŸš€

Navigate through the problem directories to explore solutions. Each directory contains the solution files, including explanations and sample input/output.

You can practice implementing your solutions and compare them with those provided.

Feel free to contribute by submitting your solutions or improvements. Open a pull request to share your contributions.

I recommend contributions for new languages, as currently, the solution is only available in Java πŸ›.

Resources πŸ“š

Happy coding and good luck with your interview preparation! πŸŽ‰