Startup / VO Interview Question: Music Service – Trending Songs (In-Memory Song Play Tracking)

14 Views
No Comments

Build a simple class that implements a basic in-memory service that:

  • Records a song play event for a given song id
  • Returns play counts for individual songs
  • Computes and returns the top K trending songs
  • Returns a SQL query that would compute trending songs from a database

This problem asks you to design a lightweight in-memory music service that tracks play counts by song id, supports count lookup for a single song, and returns the top K trending songs. A hash map is the core data structure for storing counts, while the top-K query can be solved by sorting all entries or using a min-heap for better efficiency. The database part typically translates into a GROUP BY query ordered by play count.

END
 0