🐳 LeetCode of algorithms with JavaScript solutions written in TypeScript.
Clone this project
$ git clone https://github.com/Shyam-Chen/TypeScript-Solutions
$ cd TypeScript-Solutions
Install dependencies
Run tests
$ pnpm test
# run a specific test file
$ pnpm test < FILE_NAME>
# e.g.
$ pnpm test twoSum.test.ts
解題前應該學會的思路與技巧
陣列 (Array)
鏈結串列 (Linked List)
堆疊 (Stack)
佇列 (Queue)
雜湊表 (Hash Table)
樹 (Tree)
堆積 (Heap)
圖 (Graph)
字典樹 (Trie)
排序 (Sorting)
搜尋 (Searching)
分治 (Divide and Conquer)
回溯 (Backtracking)
動態規劃 (Dynamic Programming)
貪婪 (Greedy)
位元操作 (Bit Manipulation)
Ace Coding Interview with 75 Qs
75 Essential & Trending Problems
Must-do problem list for interview prep
Best for 1~3 month of prep time
Problems:
Array / String
1768. Merge Strings Alternately
Solution
Easy
詳解
1071. Greatest Common Divisor of Strings
Solution
Easy
詳解
1431. Kids With the Greatest Number of Candies
Solution
Easy
詳解
605. Can Place Flowers
Solution
Easy
詳解
345. Reverse Vowels of a String
Solution
Easy
詳解
151. Reverse Words in a String
Solution
Medium
詳解
238. Product of Array Except Self
Solution
Medium
詳解
334. Increasing Triplet Subsequence
Solution
Medium
詳解
443. String Compression
Solution
Medium
詳解
Two Pointers
283. Move Zeroes
Solution
Easy
詳解
392. Is Subsequence
Solution
Easy
詳解
11. Container With Most Water
Solution
Medium
詳解
1679. Max Number of K-Sum Pairs
Solution
Medium
詳解
Sliding Window
643. Maximum Average Subarray I
Solution
Easy
詳解
1456. Maximum Number of Vowels in a Substring of Given Length
Solution
Medium
詳解
1004. Max Consecutive Ones III
Solution
Medium
詳解
1493. Longest Subarray of 1's After Deleting One Element
Solution
Medium
詳解
Prefix Sum
1732. Find the Highest Altitude
Solution
Easy
詳解
724. Find Pivot Index
Solution
Easy
詳解
Hash Map / Set
2215. Find the Difference of Two Arrays
Solution
Easy
詳解
1207. Unique Number of Occurrences
Solution
Easy
詳解
1657. Determine if Two Strings Are Close
Solution
Medium
詳解
2352. Equal Row and Column Pairs
Solution
Medium
詳解
Stack
2390. Removing Stars From a String
Solution
Medium
詳解
735. Asteroid Collision
Solution
Medium
詳解
394. Decode String
Solution
Medium
詳解
Queue
933. Number of Recent Calls
Solution
Easy
詳解
649. Dota2 Senate
Solution
Medium
詳解
Linked List
2095. Delete the Middle Node of a Linked List
Solution
Medium
詳解
328. Odd Even Linked List
Solution
Medium
詳解
206. Reverse Linked List
Solution
Easy
詳解
2130. Maximum Twin Sum of a Linked List
Solution
Medium
詳解
Binary Tree - DFS
104. Maximum Depth of Binary Tree
Solution
Easy
詳解
872. Leaf-Similar Trees
Solution
Easy
詳解
1448. Count Good Nodes in Binary Tree
Solution
Medium
詳解
437. Path Sum III
Solution
Medium
詳解
1372. Longest ZigZag Path in a Binary Tree
Solution
Medium
詳解
236. Lowest Common Ancestor of a Binary Tree
Solution
Medium
詳解
Binary Tree - BFS
199. Binary Tree Right Side View
Solution
Medium
詳解
1161. Maximum Level Sum of a Binary Tree
Solution
Medium
詳解
Binary Search Tree
700. Search in a Binary Search Tree
Solution
Easy
詳解
450. Delete Node in a BST
Solution
Medium
詳解
Graphs - DFS
841. Keys and Rooms
Solution
Medium
詳解
547. Number of Provinces
Solution
Medium
詳解
1466. Reorder Routes to Make All Paths Lead to the City Zero
Solution
Medium
詳解
399. Evaluate Division
Solution
Medium
詳解
Graphs - BFS
1926. Nearest Exit from Entrance in Maze
Solution
Medium
詳解
994. Rotting Oranges
Solution
Medium
詳解
Heap / Priority Queue
215. Kth Largest Element in an Array
Solution
Medium
詳解
2336. Smallest Number in Infinite Set
Solution
Medium
詳解
2542. Maximum Subsequence Score
Solution
Medium
詳解
2462. Total Cost to Hire K Workers
Solution
Medium
詳解
Binary Search
374. Guess Number Higher or Lower
Solution
Easy
詳解
2300. Successful Pairs of Spells and Potions
Solution
Medium
詳解
162. Find Peak Element
Solution
Medium
詳解
875. Koko Eating Bananas
Solution
Medium
詳解
Backtracking
17. Letter Combinations of a Phone Number
Solution
Medium
詳解
216. Combination Sum III
Solution
Medium
詳解
DP - 1D
1137. N-th Tribonacci Number
Solution
Easy
詳解
746. Min Cost Climbing Stairs
Solution
Easy
詳解
198. House Robber
Solution
Medium
詳解
790. Domino and Tromino Tiling
Solution
Medium
詳解
DP - Multidimensional
62. Unique Paths
Solution
Medium
詳解
1143. Longest Common Subsequence
Solution
Medium
詳解
714. Best Time to Buy and Sell Stock with Transaction Fee
Solution
Medium
詳解
72. Edit Distance
Solution
Medium
詳解
Bit Manipulation
338. Counting Bits
Solution
Easy
詳解
136. Single Number
Solution
Easy
詳解
1318. Minimum Flips to Make a OR b Equal to c
Solution
Medium
詳解
Trie
208. Implement Trie (Prefix Tree)
Solution
Medium
詳解
1268. Search Suggestions System
Solution
Medium
詳解
Intervals
435. Non-overlapping Intervals
Solution
Medium
詳解
452. Minimum Number of Arrows to Burst Balloons
Solution
Medium
詳解
Monotonic Stack
739. Daily Temperatures
Solution
Medium
詳解
901. Online Stock Span
Solution
Medium
詳解
Advanced - Top Interview 150
Must-do List for Interview Prep
150 Original & Classic Questions
Covers comprehensive interview topics
Best for 3+ months of prep time
Problems support high-quality editorials
Problems:
Array / String
88. Merge Sorted Array
Solution
Easy
詳解
27. Remove Element
Solution
Easy
詳解
26. Remove Duplicates from Sorted Array
Solution
Easy
詳解
80. Remove Duplicates from Sorted Array II
Solution
Medium
詳解
169. Majority Element
Solution
Easy
詳解
189. Rotate Array
Solution
Medium
詳解
121. Best Time to Buy and Sell Stock
Solution
Easy
詳解
122. Best Time to Buy and Sell Stock II
Solution
Medium
詳解
55. Jump Game
Solution
Medium
詳解
45. Jump Game II
Solution
Medium
詳解
274. H-Index
Solution
Medium
詳解
380. Insert Delete GetRandom O(1)
Solution
Medium
詳解
238. Product of Array Except Self
Solution
Medium
詳解
134. Gas Station
Solution
Medium
詳解
135. Candy
Solution
Hard
詳解
42. Trapping Rain Water
Solution
Hard
詳解
13. Roman to Integer
Solution
Easy
詳解
12. Integer to Roman
Solution
Medium
詳解
58. Length of Last Word
Solution
Easy
詳解
14. Longest Common Prefix
Solution
Easy
詳解
151. Reverse Words in a String
Solution
Medium
詳解
6. Zigzag Conversion
Solution
Medium
詳解
28. Find the Index of the First Occurrence in a String
Solution
Easy
詳解
68. Text Justification
Solution
Hard
詳解
Two Pointers
125. Valid Palindrome
Solution
Easy
詳解
392. Is Subsequence
Solution
Easy
詳解
167. Two Sum II - Input Array Is Sorted
Solution
Medium
詳解
11. Container With Most Water
Solution
Medium
詳解
15. 3Sum
Solution
Medium
詳解
Sliding Window
209. Minimum Size Subarray Sum
Solution
Medium
詳解
3. Longest Substring Without Repeating Characters
Solution
Medium
詳解
30. Substring with Concatenation of All Words
Solution
Hard
詳解
76. Minimum Window Substring
Solution
Hard
詳解
Matrix
36. Valid Sudoku
Solution
Medium
詳解
54. Spiral Matrix
Solution
Medium
詳解
48. Rotate Image
Solution
Medium
詳解
73. Set Matrix Zeroes
Solution
Medium
詳解
289. Game of Life
Solution
Medium
詳解
Hashmap
383. Ransom Note
Solution
Easy
詳解
205. Isomorphic Strings
Solution
Easy
詳解
290. Word Pattern
Solution
Easy
詳解
242. Valid Anagram
Solution
Easy
詳解
49. Group Anagrams
Solution
Medium
詳解
1. Two Sum
Solution
Easy
詳解
202. Happy Number
Solution
Easy
詳解
219. Contains Duplicate II
Solution
Easy
詳解
128. Longest Consecutive Sequence
Solution
Medium
詳解
Intervals
228. Summary Ranges
Solution
Easy
詳解
56. Merge Intervals
Solution
Medium
詳解
57. Insert Interval
Solution
Medium
詳解
452. Minimum Number of Arrows to Burst Balloons
Solution
Medium
詳解
Stack
20. Valid Parentheses
Solution
Easy
詳解
71. Simplify Path
Solution
Medium
詳解
155. Min Stack
Solution
Medium
詳解
150. Evaluate Reverse Polish Notation
Solution
Medium
詳解
224. Basic Calculator
Solution
Hard
詳解
Linked List
141. Linked List Cycle
Solution
Easy
詳解
2. Add Two Numbers
Solution
Medium
詳解
21. Merge Two Sorted Lists
Solution
Easy
詳解
138. Copy List with Random Pointer
Solution
Medium
詳解
92. Reverse Linked List II
Solution
Medium
詳解
25. Reverse Nodes in k-Group
Solution
Hard
詳解
19. Remove Nth Node From End of List
Solution
Medium
詳解
82. Remove Duplicates from Sorted List II
Solution
Medium
詳解
61. Rotate List
Solution
Medium
詳解
86. Partition List
Solution
Medium
詳解
146. LRU Cache
Solution
Medium
詳解
Binary Tree General
104. Maximum Depth of Binary Tree
Solution
Easy
詳解
100. Same Tree
Solution
Easy
詳解
226. Invert Binary Tree
Solution
Easy
詳解
101. Symmetric Tree
Solution
Easy
詳解
105. Construct Binary Tree from Preorder and Inorder Traversal
Solution
Medium
詳解
106. Construct Binary Tree from Inorder and Postorder Traversal
Solution
Medium
詳解
117. Populating Next Right Pointers in Each Node II
Solution
Medium
詳解
114. Flatten Binary Tree to Linked List
Solution
Medium
詳解
112. Path Sum
Solution
Easy
詳解
129. Sum Root to Leaf Numbers
Solution
Medium
詳解
124. Binary Tree Maximum Path Sum
Solution
Hard
詳解
173. Binary Search Tree Iterator
Solution
Medium
詳解
222. Count Complete Tree Nodes
Solution
Easy
詳解
236. Lowest Common Ancestor of a Binary Tree
Solution
Medium
詳解
Binary Tree BFS
199. Binary Tree Right Side View
Solution
Medium
詳解
637. Average of Levels in Binary Tree
Solution
Easy
詳解
102. Binary Tree Level Order Traversal
Solution
Medium
詳解
103. Binary Tree Zigzag Level Order Traversal
Solution
Medium
詳解
Binary Search Tree
530. Minimum Absolute Difference in BST
Solution
Easy
詳解
230. Kth Smallest Element in a BST
Solution
Medium
詳解
98. Validate Binary Search Tree
Solution
Medium
詳解
Graph General
200. Number of Islands
Solution
Medium
詳解
130. Surrounded Regions
Solution
Medium
詳解
133. Clone Graph
Solution
Medium
詳解
399. Evaluate Division
Solution
Medium
詳解
207. Course Schedule
Solution
Medium
詳解
210. Course Schedule II
Solution
Medium
詳解
Graph BFS
909. Snakes and Ladders
Solution
Medium
詳解
433. Minimum Genetic Mutation
Solution
Medium
詳解
127. Word Ladder
Solution
Hard
詳解
Trie
208. Implement Trie (Prefix Tree)
Solution
Medium
詳解
211. Design Add and Search Words Data Structure
Solution
Medium
詳解
212. Word Search II
Solution
Hard
詳解
Backtracking
17. Letter Combinations of a Phone Number
Solution
Medium
詳解
77. Combinations
Solution
Medium
詳解
46. Permutations
Solution
Medium
詳解
39. Combination Sum
Solution
Medium
詳解
52. N-Queens II
Solution
Hard
詳解
22. Generate Parentheses
Solution
Medium
詳解
79. Word Search
Solution
Medium
詳解
Divide & Conquer
108. Convert Sorted Array to Binary Search Tree
Solution
Easy
詳解
148. Sort List
Solution
Medium
詳解
427. Construct Quad Tree
Solution
Medium
詳解
23. Merge k Sorted Lists
Solution
Hard
詳解
Kadane's Algorithm
53. Maximum Subarray
Solution
Medium
詳解
918. Maximum Sum Circular Subarray
Solution
Medium
詳解
Binary Search
35. Search Insert Position
Solution
Easy
詳解
74. Search a 2D Matrix
Solution
Medium
詳解
162. Find Peak Element
Solution
Medium
詳解
33. Search in Rotated Sorted Array
Solution
Medium
詳解
34. Find First and Last Position of Element in Sorted Array
Solution
Medium
詳解
153. Find Minimum in Rotated Sorted Array
Solution
Medium
詳解
4. Median of Two Sorted Arrays
Solution
Hard
詳解
Heap
215. Kth Largest Element in an Array
Solution
Medium
詳解
502. IPO
Solution
Hard
詳解
373. Find K Pairs with Smallest Sums
Solution
Medium
詳解
295. Find Median from Data Stream
Solution
Hard
詳解
Bit Manipulation
67. Add Binary
Solution
Easy
詳解
190. Reverse Bits
Solution
Easy
詳解
191. Number of 1 Bits
Solution
Easy
詳解
136. Single Number
Solution
Easy
詳解
137. Single Number II
Solution
Medium
詳解
201. Bitwise AND of Numbers Range
Solution
Medium
詳解
Math
9. Palindrome Number
Solution
Easy
詳解
66. Plus One
Solution
Easy
詳解
172. Factorial Trailing Zeroes
Solution
Medium
詳解
69. Sqrt(x)
Solution
Easy
詳解
50. Pow(x, n)
Solution
Medium
詳解
149. Max Points on a Line
Solution
Hard
詳解
1D DP
70. Climbing Stairs
Solution
Easy
詳解
198. House Robber
Solution
Medium
詳解
139. Word Break
Solution
Medium
詳解
322. Coin Change
Solution
Medium
詳解
300. Longest Increasing Subsequence
Solution
Medium
詳解
Multidimensional DP
120. Triangle
Solution
Medium
詳解
64. Minimum Path Sum
Solution
Medium
詳解
63. Unique Paths II
Solution
Medium
詳解
5. Longest Palindromic Substring
Solution
Medium
詳解
97. Interleaving String
Solution
Medium
詳解
72. Edit Distance
Solution
Medium
詳解
123. Best Time to Buy and Sell Stock III
Solution
Hard
詳解
188. Best Time to Buy and Sell Stock IV
Solution
Hard
詳解
221. Maximal Square
Solution
Medium
詳解
Impactful - Top 100 Liked
100 Best Rated Problems
100 most liked problems by LeetCoders
Organized based on hot topics that help improve coding skills in interviews
Problems:
Backtracking
17. Letter Combinations of a Phone Number
Solution
Medium
詳解
22. Generate Parentheses
Solution
Medium
詳解
39. Combination Sum
Solution
Medium
詳解
46. Permutations
Solution
Medium
詳解
51. N-Queens
Solution
Hard
詳解
78. Subsets
Solution
Medium
詳解
79. Word Search
Solution
Medium
詳解
131. Palindrome Partitioning
Solution
Medium
詳解
Binary Search
4. Median of Two Sorted Arrays
Solution
Hard
詳解
33. Search in Rotated Sorted Array
Solution
Medium
詳解
34. Find First and Last Position of Element in Sorted Array
Solution
Medium
詳解
35. Search Insert Position
Solution
Easy
詳解
74. Search a 2D Matrix
Solution
Medium
詳解
124. Binary Tree Maximum Path Sum
Solution
Hard
詳解
153. Find Minimum in Rotated Sorted Array
Solution
Medium
詳解
Binary Tree
94. Binary Tree Inorder Traversal
Solution
Easy
詳解
98. Validate Binary Search Tree
Solution
Medium
詳解
101. Symmetric Tree
Solution
Easy
詳解
102. Binary Tree Level Order Traversal
Solution
Medium
詳解
104. Maximum Depth of Binary Tree
Solution
Easy
詳解
105. Construct Binary Tree from Preorder and Inorder Traversal
Solution
Medium
詳解
108. Convert Sorted Array to Binary Search Tree
Solution
Easy
詳解
114. Flatten Binary Tree to Linked List
Solution
Medium
詳解
199. Binary Tree Right Side View
Solution
Medium
詳解
226. Invert Binary Tree
Solution
Easy
詳解
230. Kth Smallest Element in a BST
Solution
Medium
詳解
236. Lowest Common Ancestor of a Binary Tree
Solution
Medium
詳解
437. Path Sum III
Solution
Medium
詳解
543. Diameter of Binary Tree
Solution
Easy
詳解
Dynamic Programming
5. Longest Palindromic Substring
Solution
Medium
詳解
32. Longest Valid Parentheses
Solution
Hard
詳解
62. Unique Paths
Solution
Medium
詳解
64. Minimum Path Sum
Solution
Medium
詳解
70. Climbing Stairs
Solution
Easy
詳解
72. Edit Distance
Solution
Medium
詳解
118. Pascal's Triangle
Solution
Easy
詳解
139. Word Break
Solution
Medium
詳解
152. Maximum Product Subarray
Solution
Medium
詳解
198. House Robber
Solution
Medium
詳解
279. Perfect Squares
Solution
Medium
詳解
300. Longest Increasing Subsequence
Solution
Medium
詳解
322. Coin Change
Solution
Medium
詳解
416. Partition Equal Subset Sum
Solution
Medium
詳解
1143. Longest Common Subsequence
Solution
Medium
詳解
Graph
200. Number of Islands
Solution
Medium
詳解
207. Course Schedule
Solution
Medium
詳解
994. Rotting Oranges
Solution
Medium
詳解
Greedy
45. Jump Game II
Solution
Medium
詳解
55. Jump Game
Solution
Medium
詳解
121. Best Time to Buy and Sell Stock
Solution
Easy
詳解
763. Partition Labels
Solution
Medium
詳解
Hashing
1. Two Sum
Solution
Easy
詳解
49. Group Anagrams
Solution
Medium
詳解
128. Longest Consecutive Sequence
Solution
Medium
詳解
560. Subarray Sum Equals K
Solution
Medium
詳解
Heap
215. Kth Largest Element in an Array
Solution
Medium
詳解
295. Find Median from Data Stream
Solution
Hard
詳解
347. Top K Frequent Elements
Solution
Medium
詳解
Linked Lists
2. Add Two Numbers
Solution
Medium
詳解
19. Remove Nth Node From End of List
Solution
Medium
詳解
21. Merge Two Sorted Lists
Solution
Easy
詳解
23. Merge k Sorted Lists
Solution
Hard
詳解
24. Swap Nodes in Pairs
Solution
Medium
詳解
25. Reverse Nodes in k-Group
Solution
Hard
詳解
138. Copy List with Random Pointer
Solution
Medium
詳解
141. Linked List Cycle
Solution
Easy
詳解
142. Linked List Cycle II
Solution
Medium
詳解
146. LRU Cache
Solution
Medium
詳解
148. Sort List
Solution
Medium
詳解
160. Intersection of Two Linked Lists
Solution
Easy
詳解
206. Reverse Linked List
Solution
Easy
詳解
234. Palindrome Linked List
Solution
Easy
詳解
Matrix
48. Rotate Image
Solution
Medium
詳解
54. Spiral Matrix
Solution
Medium
詳解
73. Set Matrix Zeroes
Solution
Medium
詳解
240. Search a 2D Matrix II
Solution
Medium
詳解
Sliding Window
3. Longest Substring Without Repeating Characters
Solution
Medium
詳解
76. Minimum Window Substring
Solution
Hard
詳解
239. Sliding Window Maximum
Solution
Hard
詳解
438. Find All Anagrams in a String
Solution
Medium
詳解
Stack
20. Valid Parentheses
Solution
Easy
詳解
84. Largest Rectangle in Histogram
Solution
Hard
詳解
155. Min Stack
Solution
Medium
詳解
394. Decode String
Solution
Medium
詳解
739. Daily Temperatures
Solution
Medium
詳解
Two Pointers
11. Container With Most Water
Solution
Medium
詳解
15. 3Sum
Solution
Medium
詳解
42. Trapping Rain Water
Solution
Hard
詳解
283. Move Zeroes
Solution
Easy
詳解
Trie
208. Implement Trie (Prefix Tree)
Solution
Medium
詳解
Misc
31. Next Permutation
Solution
Medium
詳解
41. First Missing Positive
Solution
Hard
詳解
53. Maximum Subarray
Solution
Medium
詳解
56. Merge Intervals
Solution
Medium
詳解
75. Sort Colors
Solution
Medium
詳解
136. Single Number
Solution
Easy
詳解
169. Majority Element
Solution
Easy
詳解
189. Rotate Array
Solution
Medium
詳解
238. Product of Array Except Self
Solution
Medium
詳解
287. Find the Duplicate Number
Solution
Medium
詳解