As reported: Goldman Sachs Analyst Superday DSA round (2025), first question: given the heights of buildings, return the top k tallest buildings.
Given heights of n buildings and an integer k, return the k largest heights in descending order (equal heights each count).
Example 1
heights = [3,9,4,12,7], k = 2
-> [12,9]
Example 2
heights = [5,5,1,5], k = 3
-> [5,5,5]
Constraints: 1 ≤ k ≤ n ≤ 10^5; 1 ≤ heights[i] ≤ 10^9.
Code runner format: one JSON value per line: heights, then k. Implement tallestBuildings(heights, k); the harness prints the list.