Rank Songs by Popularity

Problem Overview

  • Rank songs by popularity via pairwise beats: a song beats another if a strict majority prefers it, or if exactly half prefer it and it has a smaller id.
  • Input: n users, m songs; each user provides a permutation pref[i] of 0..m-1. Output: order songs by how many others they beat, tie-break by lower id.
  • Context: enhance a music streaming platform by aggregating user preferences into a single ranking.
  • From Expedia interviews; a coding interview interview question and ranking problem.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: