面试场景
高频考察问题建模、边界条件与口头表达的清晰度。
常见误区
只背模板不解释为什么,容易在追问里失分。
练习策略
每轮练 3-5 题,固定复盘复杂度和可替代解法。
推荐练习顺序
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…
链表随机节点
Select a random node from a singly linked list ensuring uniform probability using efficient pointer techniques and reser…
打乱数组
Shuffle an Array requires designing a class to randomly permute an integer array while ensuring all permutations are equ…
随机数索引
Random Pick Index involves selecting a random index of a target number in an array with possible duplicates.
用 Rand7() 实现 Rand10()
Generate uniform random numbers from 1 to 10 using only rand7(), applying rejection sampling for consistent probability …
在圆内随机生成点
Generate Random Point in a Circle requires creating a uniform random point inside a circle using math and geometry princ…
非重叠矩形中的随机点
Design an algorithm to pick random points within non-overlapping rectangles using binary search and reservoir sampling.
随机翻转矩阵
Design an optimized algorithm to randomly flip an index in a matrix, using hash tables and math for efficient random sel…
按权重随机选择
Random Pick with Weight requires implementing a probabilistic index picker using prefix sums and binary search efficient…
黑名单中的随机数
Random Pick with Blacklist requires designing a method to uniformly pick integers while excluding blacklisted values eff…
服务中心的最佳位置
Find the optimal service center position in a city by minimizing the sum of Euclidean distances to all customers.