Facebook Interview Question | 2020

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2020-09-13Added By Anonymous
Source: Link

Company: Meta (Facebook)
Role: e3, e4
Interview Stage: Phone Screen
Location: unknown
Year: 2020

Original Post Content:

You are given a music library of size 'numberOfSongs', you have to create playlist of size at least 'sizeOfPlaylist'.

After a song is played, at least 'betweenRepeat' number of songs should be played before repeating the song.

Return number of playlists possible.

eg: numberOfSongs = 3, betweenRepeat = 2, sizeOfPlaylist = 4
playlists possible: [1,2,3,1], [1,3,2,1], [2,1,3,2], [2,3,1,2], [3,1,2,3], [3,2,1,3]
return 6.

eg: numberOfSongs = 1, betweenRepeat = 0, sizeOfPlaylist = 3
playlists possible: [1,1,1]
return 1.

eg: numberOfSongs = 1, betweenRepeat = 1, sizeOfPlaylist = 3
playlists possible: NULL, as you have to wait 1 songs to repeat 1, to get playlist of size 3.
return 0.

Comments