Top K Selection
2026/3/9小于 1 分钟
Top K Selection
题面
实现对长度 N 的 float32 数组选取前 k 大元素,并按降序写入长度 k 的输出数组。
Implementation Requirements
- External libraries are not permitted
- The solve function signature must remain unchanged
- The final result must be stored in the output array
Examples
Input: [1.0, 5.0, 3.0, 2.0, 4.0], k=3 → [5.0, 4.0, 3.0]
Input: [7.2, -1.0, 3.3, 8.8, 2.2], k=2 → [8.8, 7.2]Constraints
- 1 ≤ N ≤ 100,000,000
- 1 ≤ k ≤ N
- values 为 float32;Performance: N = 50,000,000, k = 100