Heap and ranking: Return the k most frequent distinct values in nums, ordered by descending frequency and then ascending numeric value for ties.
Input: A JSON object { "nums": number[], "k": number }.
Output: A JSON number[] containing at most k distinct values in the required order.
Constraints:
- 0 <= nums.length <= 100000
- 0 <= k <= number of distinct values
- Tie-breaking by numeric value is mandatory
Read one JSON value from stdin and print exactly one JSON-serialized answer to stdout with no extra text.
Difficulty: HARD. Variant: 3. Balance correctness, maintainability, and clear review-ready code.
Practice context
This coding (algo) exercise trains prompt interpretation, explicit assumptions, a concrete response, and a concise explanation of the decisions made. It is marked hard difficulty.
The signed-in workspace provides the tools required by the round, such as recor