最佳练习题
Blind 75 作者整理的 5 周算法面试练习题清单
Tip
截至 2022 年 4 月,我整理了一个 12-week study plan,包含复习与练习题的完整路径。如果你想自定义练习题,我也做了 Grind 75,它是 Blind 75 的现代版本,可以自己调整。
我是 Blind 75 的作者 👋!
练习是准备 coding interview 最好的方法。LeetCode 有上千道题,该练哪些?所以多年前我整理了 LeetCode 上最重要的 75 题清单。很多其他题其实就是这些题的技巧组合。我上一次找工作时就只刷这份清单里的题。
我把这份清单从 freeCodeCamp 文章 抽出来并分享在 Blind,后来有人转载到 LeetCode 论坛。没想到它火了,大家给它起了名字 Blind 75。Blind 75 的 LeetCode list 在 这里。
几年后,我进一步精简到 50 题,并分配到 5 周计划。下面是建议的复习与练习节奏。还没有账号的话尽快注册一个 LeetCode 账号,这对面试成功很关键!
练习时建议把它当成真实面试:提交前仔细检查,甚至手动设计测试用例并跑一遍,验证正确性。
我为以下题目创建了一个 LeetCode list(不包含 Premium 题),可以用来追踪进度。
Tip: Expert tip
如果时间紧张,AlgoMonster 的目标是让你 在最短时间内 拿下面试。由 Google 工程师打造,AlgoMonster 用数据驱动的方法讲解最重要的题型模式,并提供快速复习基础数据结构和算法的内容。学会模式,不是死记答案!
Week 1 - Sequences
第 1 周做热身,刷 array/string 的 easy + medium 题。数组和字符串是面试中最常见题型,打好基础会让你更容易应对后面的硬题。
| Question | Difficulty | LeetCode |
|---|---|---|
| Two Sum | Easy | Link |
| Contains Duplicate | Easy | Link |
| Best Time to Buy and Sell Stock | Easy | Link |
| Valid Anagram | Easy | Link |
| Valid Parentheses | Easy | Link |
| Maximum Subarray | Easy | Link |
| Product of Array Except Self | Medium | Link |
| 3Sum | Medium | Link |
| Merge Intervals | Medium | Link |
| Group Anagrams | Medium | Link |
Optional
| Question | Difficulty | LeetCode |
|---|---|---|
| Maximum Product Subarray | Medium | Link |
| Search in Rotated Sorted Array | Medium | Link |
Week 2 - Data structures
第 2 周聚焦 linked list、string、matrix。重点掌握 linked list 常规操作、matrix traversal,以及序列分析技巧(sliding window 等)。
| Question | Difficulty | LeetCode |
|---|---|---|
| Reverse a Linked List | Easy | Link |
| Detect Cycle in a Linked List | Easy | Link |
| Container With Most Water | Medium | Link |
| Find Minimum in Rotated Sorted Array | Medium | Link |
| Longest Repeating Character Replacement | Medium | Link |
| Longest Substring Without Repeating Characters | Medium | Link |
| Number of Islands | Medium | Link |
| Remove Nth Node From End Of List | Medium | Link |
| Palindromic Substrings | Medium | Link |
| Pacific Atlantic Water Flow | Medium | Link |
| Minimum Window Substring | Hard | Link |
Week 3 - Non-linear data structures
第 3 周聚焦树、图、堆等非线性结构。熟悉各种树遍历(in-order、pre-order、post-order)和图遍历(BFS/DFS)。更高级的图算法(Dijkstra、Floyd-Warshall)在面试里很少见,通常用不上。
| Question | Difficulty | LeetCode |
|---|---|---|
| Invert/Flip Binary Tree | Easy | Link |
| Validate Binary Search Tree | Medium | Link |
| Non-overlapping Intervals | Medium | Link |
| Construct Binary Tree from Preorder and Inorder Traversal | Medium | Link |
| Top K Frequent Elements | Medium | Link |
| Clone Graph | Medium | Link |
| Course Schedule | Medium | Link |
| Serialize and Deserialize Binary Tree | Hard | Link |
| Binary Tree Maximum Path Sum | Hard | Link |
Optional
| Question | Difficulty | LeetCode |
|---|---|---|
| Maximum Depth of Binary Tree | Easy | Link |
| Same Tree | Easy | Link |
| Binary Tree Level Order Traversal | Medium | Link |
| Encode and Decode Strings | Medium | Link (Premium) |
Week 4 - More data structures
第 4 周难度上升,会更接近真实面试的强度。除了前几周的内容,也会涉及更高级但仍常考的数据结构,比如 heap 和 trie。
| Question | Difficulty | LeetCode |
|---|---|---|
| Subtree of Another Tree | Easy | Link |
| Lowest Common Ancestor of BST | Easy | Link |
| Implement Trie (Prefix Tree) | Medium | Link |
| Add and Search Word | Medium | Link |
| Kth Smallest Element in a BST | Medium | Link |
| Merge K Sorted Lists | Hard | Link |
| Find Median from Data Stream | Hard | Link |
| Insert Interval | Medium | Link |
| Longest Consecutive Sequence | Medium | Link |
| Word Search II | Hard | Link |
Optional
| Question | Difficulty | LeetCode |
|---|---|---|
| Meeting Rooms | Easy | Link (Premium) |
| Meeting Rooms II | Medium | Link (Premium) |
| Graph Valid Tree | Medium | Link (Premium) |
| Number of Connected Components in an Undirected Graph | Medium | Link (Premium) |
| Alien Dictionary | Hard | Link (Premium) |
Week 5 - Dynamic programming
第 5 周聚焦 Dynamic Programming(DP)。作为面试官,我个人不太喜欢 DP 题,因为它在真实工作中用得少,而且如果当年我面试时被问到很难的 DP 题,我可能也拿不到 offer。不过 Google 等公司仍会考 DP,如果你目标是这些公司,DP 就不可避免。
DP 题的难点在于掌握套路,最好的办法只有练。熟悉 memoization 与 backtracking 等概念。
从 ROI 角度看,刷 DP 的投入产出比不高,所以可以视为可选内容。只有在你时间充裕且想“全覆盖”(比如目标 Google)时,再深入刷。
| Question | Difficulty | LeetCode |
|---|---|---|
| Climbing Stairs | Easy | Link |
| Coin Change | Medium | Link |
| Longest Increasing Subsequence | Medium | Link |
| Combination Sum | Medium | Link |
| House Robber | Medium | Link |
| House Robber II | Medium | Link |
| Decode Ways | Medium | Link |
| Unique Paths | Medium | Link |
| Jump Game | Medium | Link |
| Word Break | Medium | Link |
Dynamic programming course
Quality courses
如果你想更结构化地练算法,推荐这些课程: