I was asked this question in an interview, and I gave various solutions, but the interviewer was not convinced. I am interested in finding a solution. Please enter your opinions:
Q: Write an efficient data structure for implementing shuffling on ipod. He must play all the songs, each time in different random order, the same song should not be repeated. (mostly O (n))
One solution I thought after the interview: I can do a randomized quick sort without recursion. Where we randomly selected 1 pivot O (1) and then do quicksort O (n). Now the songs will be sorted in a certain order, and I will play them to the end. As soon as it reaches the end, I will again select a random rod and repeat this process again and again.
Regards, Sethu
sethu source
share