Microsoft Interview Question
Software Engineer / DevelopersQ. Pick a random song from a playlist such that you dont repeat until you are done with all songs in the playlist.
A. I would use a List (due to constant time remove/insert). generate a random number less than size of list. pick song with that index and remove from list. re-initialize the list to start over.
I would use a array(n) to hold the songs in a playlist.
Generate a random number with seed between 0 to n.
Play the song at that index.
Swap the played song with the last song in the array.
Now again generate a random number with seed between 0 to n-1.
Once played swap with n-1 element.The process continues.
Adavntage is you dont require to change the array structure apart from swapping values.
What's the question here? Is it to:
- confused March 23, 2010Design the random play (shuffle) feature?
Code a random selection?
Test the random play?
Pick a random playlist?
As you can see from my post, there's no 10 word limitation on a question (or answer). Please reduce the signal to noise ratio here by posting concise, coherent questions.