Given unsorted lists of tracks per country (Track: id, country, count, genre), implement getBestNTracksinACountry(String country, int n) and getBestNTracksGlobally(int n) summing counts across countries.
Asked in the Onsite - Coding stage. The interviewer preferred plain sorting over quickselect. Reported follow-up: What happens if we got these requests too often?
Use Python dictionaries with keys id, country, count, and genre. Each function receives tracks, country, and n; pass country=None for the global operation. Return up to n track IDs, ordered by descending summed count, then ascending ID for ties. The country operation only includes matching records; the global operation sums every country.
def getBestNTracksinACountry(tracks, country, n):