← 返回 uber 的题目列表Online Clustering for a Number Stream
类型:online_judge
You are given a number stream x1, x2, ... (one integer/float arrives at a time). Design and implement an online clustering algorithm.
Interview requirements:
You may choose any clustering approach (e.g., online k-means, threshold-based incremental clustering, sliding-window clustering) and justify your choice.
Implement the core logic: when a new value x arrives, assign it to a cluster and update that cluster’s statistics (e.g., center/mean, count).
Output: for each incoming x, output the assigned cluster_id (0-indexed).
You must define (and state) the following choices
Whether the number of clusters is fixed (k) or can grow dynamically.
Distance metric (e.g., 1D Euclidean distance |x - center|).
Initialization strategy.
(Optional) sliding window or decay factor to handle drift.
Suggested input
Line 1: if using fixed k, an integer k (otherwise omitted).
Line 2: integer n.
Line 3: n numbers (or n lines each one number).
Output
n lines, each a cluster_id.
Example
Input
2
6
1 2 10 11 12 3
Output
0
1
1
1
1
0