Back to Amazon
Amazon logo

Coding rounds

Amazon coding rounds

5 timed coding challenges drawn from real loops. Submit a solution to see your test pass rate and AI feedback.

All coding rounds
intermediate 40:00+90 XP

Top K Frequent Elements

Given an integer array `nums` and an integer `k`, return the `k` most frequent elements. You may return the answer in any order. Aim for better than O(n log n) using bucket sort by frequency.

Examples

  • 1 appears 3x, 2 appears 2x

    in: nums=[1,1,1,2,2,3], k=2

    out: [1,2]

  • single element

    in: nums=[1], k=1

    out: [1]

javascript
Loading editor...