Amazon VO 面试真题解析:流式浮点数中查找距离不超过 d 的三元组

17次阅读
没有评论

Your task is to write a function that, given a distance d and a stream of floating-point values received one at a time, checks for groups of three values that are within at most d distance.

As values are received, they should be stored in memory.

Whenever any group is found meeting the distance criteria, return the three values and remove them from memory.

这道题考察的是流式数据处理和区间匹配:输入是一个不断到来的浮点数序列,需要在内存中维护已接收的值,并尽快找出任意三个数,使得它们之间的距离满足题目要求。常见思路是先将数据按数值有序维护,或在滑动窗口 / 平衡搜索结构中持续查询当前值附近是否能组成合法三元组;一旦找到,就立刻返回这三个值并从存储中删除。核心在于高效地支持“插入、查找邻近值、删除”这三类操作。

正文完
 0