Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Random Song Playlist Shuffle
00:00
5 left

Random Song Playlist Shuffle

MediumPython

Problem

NiCE CXone needs to generate randomized song queues for a playlist simulation. Given a list of unique song identifiers, produce a separate random ordering for each iteration. Every iteration must contain every song exactly once, and the input order must remain unchanged.

Use a deterministic pseudo-random sequence controlled by seed so the result can be reproduced during testing. Implement the shuffle with the Fisher-Yates algorithm. You may use a linear congruential generator for pseudo-random indices:

state = (state * 1664525 + 1013904223) mod 2^32

For each position i from the end of the list down to 1, use state mod (i + 1) as the swap index.

Formal Specification

Implement generate_song_iterations(songs, iterations, seed), where songs is a list of unique strings, iterations is a nonnegative integer, and seed is a nonnegative integer. Return a list containing iterations shuffled copies of songs.

Constraints

  • 0 <= len(songs) <= 10^5
  • 0 <= iterations <= 10^3
  • 0 <= seed < 2^32
  • Song identifiers are unique strings
  • The input list must not be modified

Function Signature

def generate_song_iterations(songs, iterations, seed):
Interviewer

Your question is Random Song Playlist Shuffle. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.