Leetcode Top Interview ๐ฏ
Last updated
Last updated
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.
Show some โค๏ธ by starring โญ this repository if you like it!
Contact for work, email: chunhthanhde.dev@gmail.com
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.
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.
Array / String
1
Easy
๐ข
โ
2
Easy
๐ข
โ
3
Easy
๐ข
โ
4
Medium
๐ก
โ
5
Easy
๐ข
โ
6
Medium
๐ก
โ
7
Easy
๐ข
โ
8
Medium
๐ก
โ
9
Medium
๐ก
โ
10
Medium
๐ก
โ
11
Medium
๐ก
โ
12
Medium
๐ก
โ
13
Medium
๐ก
โ
14
Medium
๐ก
โ
15
Hard
๐ด
โ
16
Hard
๐ด
โ
17
Easy
๐ข
โ
18
Medium
๐ก
โ
19
Easy
๐ข
โ
20
Easy
๐ข
โ
21
Medium
๐ก
โ
22
Medium
๐ก
โ
23
Easy
๐ข
โ
24
Hard
๐ด
โ
Two Pointers
25
Easy
๐ข
โ
26
Easy
๐ข
โ
27
Medium
๐ก
โ
28
Medium
๐ก
โ
29
Medium
๐ก
โ
Sliding Window
30
Medium
๐ก
โ
31
Medium
๐ก
โ
32
Hard
๐ด
โ
33
Hard
๐ด
โ
Matrix
34
Medium
๐ก
โ
35
Medium
๐ก
โ
36
Medium
๐ก
โ
37
Medium
๐ก
โ
38
Medium
๐ก
โ
Hashmap
39
Easy
๐ข
โ
40
Easy
๐ข
โ
41
Easy
๐ข
โ
42
Easy
๐ข
โ
43
Medium
๐ก
โ
44
Easy
๐ข
โ
45
Easy
๐ข
โ
46
Easy
๐ข
โ
47
Medium
๐ก
โ
Intervals
48
Easy
๐ข
โ
49
Medium
๐ก
โ
50
Medium
๐ก
โ
51
Medium
๐ก
โ
Stack
52
Easy
๐ข
โ
53
Medium
๐ก
โ
54
Medium
๐ก
โ
55
Medium
๐ก
โ
56
Hard
๐ด
โ
Linked List
57
Easy
๐ข
โ
58
Medium
๐ก
โ
59
Easy
๐ข
โ
60
Medium
๐ก
โ
61
Medium
๐ก
โ
62
Hard
๐ด
โ
63
Medium
๐ก
โ
64
Medium
๐ก
โ
65
Medium
๐ก
โ
66
Medium
๐ก
โ
67
Medium
๐ก
โ
Binary Tree General
68
Easy
๐ข
โ
69
Easy
๐ข
โ
70
Easy
๐ข
โ
71
Easy
๐ข
โ
72
Medium
๐ก
โ
73
Medium
๐ก
โ
74
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
๐ก
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.
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.
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 ๐.
Happy coding and good luck with your interview preparation! ๐