题库chevron_right分类chevron_right随机化
casino

随机化

12 道题目
简单: 0中等: 9困难: 3

随机化 是技术面试里最常出现的能力维度之一。建议先掌握基础题型的边界处理,再逐步过渡到模式识别和复杂度 trade-off。

面试场景

高频考察问题建模、边界条件与口头表达的清晰度。

常见误区

只背模板不解释为什么,容易在追问里失分。

练习策略

每轮练 3-5 题,固定复盘复杂度和可替代解法。

推荐练习顺序

#题目难度
380

O(1) 时间插入、删除和获取随机元素

Implement a data structure supporting insert, delete, and getRandom in average O(1) using array plus hash mapping.

中等
381

O(1) 时间插入、删除和获取随机元素 - 允许重复

This problem challenges you to design a data structure that supports insertion, removal, and random access with O(1) tim…

困难
382

链表随机节点

Select a random node from a singly linked list ensuring uniform probability using efficient pointer techniques and reser…

中等
384

打乱数组

Shuffle an Array requires designing a class to randomly permute an integer array while ensuring all permutations are equ…

中等
398

随机数索引

Random Pick Index involves selecting a random index of a target number in an array with possible duplicates.

中等
470

用 Rand7() 实现 Rand10()

Generate uniform random numbers from 1 to 10 using only rand7(), applying rejection sampling for consistent probability …

中等
478

在圆内随机生成点

Generate Random Point in a Circle requires creating a uniform random point inside a circle using math and geometry princ…

中等
497

非重叠矩形中的随机点

Design an algorithm to pick random points within non-overlapping rectangles using binary search and reservoir sampling.

中等
519

随机翻转矩阵

Design an optimized algorithm to randomly flip an index in a matrix, using hash tables and math for efficient random sel…

中等
528

按权重随机选择

Random Pick with Weight requires implementing a probabilistic index picker using prefix sums and binary search efficient…

中等
710

黑名单中的随机数

Random Pick with Blacklist requires designing a method to uniformly pick integers while excluding blacklisted values eff…

困难
1515

服务中心的最佳位置

Find the optimal service center position in a city by minimizing the sum of Euclidean distances to all customers.

困难

关联高频模式

LeetCode 随机化题型题解:12题训练路线