← Microsoft questions

Find K most frequently used elements and sort 0s, 1s, 2s

Filed under Microsoft

Solve two common array tasks: 1) Given an integer array `nums` and an integer `k`, return the `k` most frequent elements. 2) Given an array `nums` containing only integers 0, 1, and 2, sort the array…

You've read your 3 free write-ups

Sign up free to keep reading. Your account opens the first 10 questions of every company.

Related Microsoft questions

Collected from public candidate posts and coding forums. Updated Nov 2026.