面试场景
高频考察问题建模、边界条件与口头表达的清晰度。
常见误区
只背模板不解释为什么,容易在追问里失分。
练习策略
每轮练 3-5 题,固定复盘复杂度和可替代解法。
推荐练习顺序
LRU 缓存
Implement an efficient LRU Cache using hash table and doubly-linked list to achieve O(1) operations for get and put.
最小栈
Design a stack with O(1) operations to push, pop, retrieve the top element, and get the minimum element in constant time…
二叉搜索树迭代器
Implement an iterator for in-order traversal of a binary search tree (BST), maintaining traversal state with stack-based…
实现 Trie (前缀树)
This problem requires designing a Trie (Prefix Tree) to efficiently store and query strings using hash table concepts fo…
添加与搜索单词 - 数据结构设计
Build a WordDictionary supporting dynamic word addition and search with wildcard matching efficiently using Trie and DFS…
用队列实现栈
This problem tests your ability to simulate a LIFO stack using two queues while preserving all standard stack operations…
用栈实现队列
Implement a queue using two stacks, focusing on stack-based state management to achieve FIFO behavior in a queue.
窥视迭代器
Design an iterator with peek functionality, adding to the standard next and hasNext operations for efficient element acc…
数据流的中位数
Implement a MedianFinder class that supports adding numbers and finding the median from a data stream.
二叉树的序列化与反序列化
This problem asks to serialize and deserialize a binary tree, requiring an efficient approach to handle traversal and st…
区域和检索 - 数组不可变
The Range Sum Query - Immutable problem involves implementing a data structure to handle range sum queries efficiently.
二维区域和检索 - 矩阵不可变
Design a 2D matrix class that efficiently handles sum queries with O(1) time complexity using a prefix sum approach.
区域和检索 - 数组可修改
Implement a mutable range sum query using efficient design patterns to handle multiple updates and range sum queries.
扁平化嵌套列表迭代器
Implement an iterator to flatten a nested list of integers, accounting for potential nesting levels.
将数据流变为多个不相交区间
The problem involves designing a class to summarize a data stream of non-negative integers as disjoint intervals using b…
设计推特
Design Twitter requires implementing post, follow, unfollow, and news feed retrieval using linked-list pointer manipulat…
O(1) 时间插入、删除和获取随机元素
Implement a data structure supporting insert, delete, and getRandom in average O(1) using array plus hash mapping.
O(1) 时间插入、删除和获取随机元素 - 允许重复
This problem challenges you to design a data structure that supports insertion, removal, and random access with O(1) tim…
打乱数组
Shuffle an Array requires designing a class to randomly permute an integer array while ensuring all permutations are equ…
全 O(1) 的数据结构
Implement a data structure that tracks string counts and retrieves max or min keys efficiently in constant time.
序列化和反序列化二叉搜索树
Design an algorithm to serialize and deserialize a binary search tree with efficient traversal and state tracking.
LFU 缓存
Implement an LFU Cache using linked-list pointer manipulation with constant-time get and put operations for interview sc…
TinyURL 的加密与解密
Design a class that encodes and decodes URLs using a URL shortening approach based on hash tables and strings.
设计循环队列
Design a circular queue that allows efficient FIFO operations using linked-list pointer manipulation to optimize space u…
设计循环双端队列
Design and implement a circular deque using linked-list pointer manipulation, ensuring efficient insertion and deletion …
实现一个魔法字典
Design a Magic Dictionary to allow searching with one-character modifications, using Hash Table and String techniques.
键值映射
Design and implement a data structure that supports efficient insertion and sum queries based on string prefixes.
数据流中的第 K 大元素
Find the kth largest element in a dynamic stream using binary-tree traversal and efficient state tracking with a min-hea…
设计哈希集合
Implement a custom HashSet without built-in libraries using array scanning and hash lookup for efficient membership chec…
设计哈希映射
Implement a custom HashMap from scratch using array scanning and hash lookup without built-in libraries for efficient ke…
设计链表
Implement a custom linked list supporting head, tail, index insertions, retrieval, and deletions efficiently with pointe…
Range 模块
Design a RangeModule to track and query half-open intervals using segment trees or ordered sets.
我的日程安排表 I
Implement a calendar supporting non-overlapping event bookings using binary search for efficient insertion and conflict …
我的日程安排表 II
Implement a calendar that allows double bookings but prevents triple bookings, managing overlapping intervals efficientl…
我的日程安排表 III
Implement My Calendar III to track maximum overlapping events efficiently using binary search and segment tree technique…
前缀和后缀搜索
Design a dictionary to search words by both prefix and suffix using a Trie structure and hash lookups.
考场就座
Simulate an exam room where each student chooses a seat maximizing distance to others, using design plus heap structures…
最大频率栈
Design a stack-like data structure to manage elements and handle frequent stack operations, including popping the most f…
RLE 迭代器
Design an efficient iterator for a run-length encoded array, handling large counts and sequential access correctly every…
股票价格跨度
Design an efficient algorithm using stacks to calculate the stock span for daily price quotes.
在线选举
Solve the Online Election problem by implementing a class that tracks votes and queries the leading candidate at any giv…
完全二叉树插入器
Implement a data structure to insert nodes into a complete binary tree while preserving its completeness efficiently.
最近的请求次数
The "Number of Recent Calls" problem involves designing a class to efficiently track recent requests within a time windo…
基于时间的键值存储
Implement a time-based key-value store that retrieves the latest value at a given timestamp using efficient binary searc…
字符流
Implement a StreamChecker that detects if any suffix of a character stream matches a given list of words using efficient…
快照数组
Implement a SnapshotArray that efficiently tracks element changes and retrieves past states using array scanning and has…
子数组中占绝大多数的元素
Efficiently find the majority element in any subarray using a data structure optimized for multiple range queries.
餐盘栈
Design a system that manages dinner plate stacks using stack-based state management, handling dynamic plate placement an…
设计跳表
Implement a Skiplist efficiently using linked-list pointer manipulation to support search, add, and erase operations in …
在受污染的二叉树中查找元素
Recover values in a contaminated binary tree and efficiently check for existence using traversal and state tracking tech…
字母组合迭代器
Implement an iterator that generates all combinations of a given length using efficient backtracking with pruning.
推文计数
Design an efficient solution to track and retrieve tweet counts over different frequencies using binary search and hash …
最后 K 个数的乘积
Design a data structure to efficiently return the product of the last k numbers in a dynamic integer stream using prefix…
每隔 n 个顾客打折
Compute customer bills with periodic discounts efficiently using array scanning and hash mapping for fast product price …
设计一个支持增量操作的栈
Implement a stack that supports push, pop, and targeted increment operations efficiently using array-based state managem…
设计地铁系统
Design an underground system to calculate travel times between stations using hash tables for efficient lookups and aver…
设计浏览器历史记录
Implement a browser history tracker with back, forward, and visit operations using linked-list pointer manipulation effi…
子矩形查询
Implement the SubrectangleQueries class to handle dynamic updates and value queries on a 2D rectangle.
树节点的第 K 个祖先
Find the kth ancestor of any node in a tree using efficient binary-tree traversal and dynamic state tracking methods.
王位继承顺序
Throne Inheritance requires modeling a dynamic family tree with births and deaths to determine the kingdom's inheritance…
设计停车系统
Implement a class to manage a parking lot with fixed slots for big, medium, and small cars, tracking occupancy efficient…
奇妙序列
Implement a Fancy sequence supporting append, addAll, and multAll operations efficiently using cumulative math design te…
设计有序流
Design an Ordered Stream that returns values in increasing order based on unique integer IDs with efficient insertion an…
设计前中后队列
Implement a queue that efficiently handles push and pop operations at the front, middle, and back using pointer manipula…
设计一个验证系统
Implement an AuthenticationManager using linked-list pointer manipulation and a hash map to track token expirations effi…
求出 MK 平均值
Find the MKAverage of a stream of integers using a queue-driven approach with efficient state management.
座位预约管理系统
Manage seat reservations efficiently using a design combining priority queue to always return the lowest available seat …
找出和为指定值的下标对
Efficiently track and count pairs across two arrays using array scanning plus hash lookup to support dynamic updates.
设计电影租借系统
Implement a movie rental system with efficient search, rent, drop, and report operations using arrays and hash lookups.
树上的操作
Design a tree data structure that allows locking, unlocking, and upgrading nodes with user-specific actions.
检测正方形
Detect Squares requires tracking points on a 2D plane to quickly count all possible axis-aligned squares using efficient…
股票价格波动
Design an efficient algorithm for managing stock price fluctuations with incorrect and unordered data in a data stream.
简易银行系统
Design a simple bank system that processes transactions like withdrawals, deposits, and transfers while managing account…
模拟行走机器人 II
The Walking Robot Simulation II problem challenges you to simulate robot movements and track its position and direction …
区间内查询数字的频率
Design a data structure to handle efficient frequency queries for subarrays, focusing on hash-based lookups and efficien…
序列顺序查询
Track rankings of locations with names and scores, adding new locations and retrieving top-ranked ones efficiently.
设计位集
Master the Design Bitset problem by efficiently managing bit flips, counts, and indexed updates with array and hash look…
加密解密字符串
The 'Encrypt and Decrypt Strings' problem involves creating a data structure that can encrypt and decrypt strings using …
设计一个 ATM 机器
Design an ATM machine that stores and withdraws money with given denominations and prioritizes larger values during with…
统计区间中的整数数目
Design and implement a data structure to efficiently add intervals and count the total number of integers covered by the…
以组为单位订音乐会的门票
Design a ticketing system to allocate concert seats in specific groupings while efficiently handling seat reservations.
设计一个文本编辑器
Design a text editor that supports text manipulation and cursor navigation operations efficiently with linked-list-based…
无限集中的最小数字
Design a data structure to handle the smallest missing element in an infinite set, with the ability to add and remove el…
设计数字容器系统
Learn to implement a Number Container System using hash tables and design techniques to efficiently track numbers and in…
设计食物评分系统
Design a food rating system that tracks and updates ratings of foods, finding the highest rated items by cuisine.
最长上传前缀
Calculate the longest continuous uploaded prefix in a video stream efficiently using a mix of binary search and data str…
设计内存分配器
Design a memory allocator that simulates allocation and deallocation of memory blocks.
找到数据流中的连续整数
Design a data stream checker to identify consecutive integers from a stream, focusing on handling state transitions effi…
设计可以求最短路径的图类
Implement a dynamic weighted directed graph with efficient shortest path queries and edge additions in real time.
频率跟踪器
Design a data structure to track values and answer frequency-related queries efficiently using hash tables.
设计相邻元素求和服务
Design a service that computes sums for adjacent and diagonal elements in a 2D grid.
设计任务管理器
Design a Task Manager that can efficiently handle task management operations such as adding, editing, executing, and rem…
设计电子表格
Design a spreadsheet that supports setting, retrieving, and resetting values, with the ability to handle formulas refere…
设计路由器
Efficiently design a Router class to manage network packets with memory limits using array scanning and hash lookups.