PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Amazon

Design a no-repeat top-frequency music player

Last updated: Mar 29, 2026

Quick Overview

This question evaluates design and implementation skills in dynamic data structures and algorithms, specifically frequency counting, priority selection, streaming updates, and cycle-based exclusion for scheduling songs.

  • medium
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Design a no-repeat top-frequency music player

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are building a music player that receives a stream of new users and their song lists. Each event is: - addUserSongs(userId, songs): a new user arrives with a list of song IDs (strings or ints). Each appearance of a song in the input increases that song’s global frequency by 1. You must support: - getNextSong(): returns the song ID to play next. Playback rules: 1) Always choose, among songs that have **not yet been played in the current cycle**, the song with the **highest global frequency**. 2) A song cannot be replayed within the same cycle. 3) Once **every known song** has been played once in the current cycle, the cycle resets (all songs become eligible again), and selection continues. 4) New songs may arrive at any time; they should be considered immediately as eligible (unless already played in the current cycle). If multiple eligible songs tie on frequency, you may break ties arbitrarily (or specify a deterministic tie-break such as lexicographically smallest ID). Design the data structures and implement these APIs efficiently. Discuss time complexity. You may assume up to 1e5 total song additions and 1e5 getNextSong calls.

Quick Answer: This question evaluates design and implementation skills in dynamic data structures and algorithms, specifically frequency counting, priority selection, streaming updates, and cycle-based exclusion for scheduling songs.

Related Interview Questions

  • Implement Datacenter Router Commands - Amazon (hard)
  • Replace Delimited Tokens in a String - Amazon (medium)
  • Minimize Circular Redistribution Cost - Amazon (medium)
  • Find the Most Common Visit Pattern - Amazon (hard)
  • Maximize Value Under a Budget - Amazon (medium)
Amazon logo
Amazon
Mar 22, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
2
0

You are building a music player that receives a stream of new users and their song lists.

Each event is:

  • addUserSongs(userId, songs): a new user arrives with a list of song IDs (strings or ints). Each appearance of a song in the input increases that song’s global frequency by 1.

You must support:

  • getNextSong(): returns the song ID to play next.

Playback rules:

  1. Always choose, among songs that have not yet been played in the current cycle , the song with the highest global frequency .
  2. A song cannot be replayed within the same cycle.
  3. Once every known song has been played once in the current cycle, the cycle resets (all songs become eligible again), and selection continues.
  4. New songs may arrive at any time; they should be considered immediately as eligible (unless already played in the current cycle).

If multiple eligible songs tie on frequency, you may break ties arbitrarily (or specify a deterministic tie-break such as lexicographically smallest ID).

Design the data structures and implement these APIs efficiently. Discuss time complexity. You may assume up to 1e5 total song additions and 1e5 getNextSong calls.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Amazon•More Software Engineer•Amazon Software Engineer•Amazon Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.