Company: Uber_14july
Difficulty: medium
Song Popularity Problem Description As part of enhancing a music streaming platform's user experience, implement a feature that ranks songs by their popularity. Given n users and m songs, each user i has a preference list, pref[i] , which is a permutation of numbers 0 to m-1 , indicating the user's preference for a song. If a , the user prefers song pref[a] over song pref[b] . To rank the songs, use the following approach. Song x is said to beat song y if x is preferred over y by more than half of the users or if exactly half of the users prefer x over y and x has a smaller id. Song x is considered more popular than song y if x beats more songs than y . If x and y beat the same number of songs, select the song with a lower id. Examples Example 1: Suppose n = 3 , m = 3 , pref = [[0, 1, 2], [0, 2, 1], [1, 2, 0]] User Song Preference: User 0: Song 0 > Song 1 > Song 2 User 1: Song 0 > Song 2 > Song 1 User 2: Song 1 > Song 2 > Song 0 Comparisons: Song 0 > Song 1: Users 0, 1 prefer Song 0 ov