Company: Pubmatic_17_jan
Difficulty: medium
Shuffle Playlist Shuffle Playlist Description Given a playlist, an array consisting of n songs where playlist[i] = [title, artist] , implement a smart shuffle that avoids consecutive songs by the same artist, following these rules: Pick the artist with the most remaining unplayed songs. Break ties by the artist whose first song appears earliest in the original playlist. Avoid picking the same artist as the previous song unless only one artist has songs left. For each artist, preserve the original relative order of their songs in the playlist. Output the [title, artist] pairs in the order they should be played. Example Input: playlist = [ ["Photograph", "EdSheeran"], ["Perfect", "EdSheeran"], ["BlindingLights", "TheWeeknd"], ["Shivering", "EdSheeran"], ["Tides", "EdSheeran"], ["BlankSpace", "TaylorSwift"] ] Output: [ ["Photograph", "EdSheeran"], ["BlindingLights", "TheWeeknd"], ["Perfect", "EdSheeran"], ["BlankSpace", "TaylorSwift"], ["Shivering", "EdSheeran"], ["Tides", "EdSheeran"] ]