Company: Agoda SDE 6m Offcampus_18july
Difficulty: medium
An array playlist of size n is given, where each element is a pair: [title, artist] Reorder the songs to produce a smart shuffle using the following rules: At each step, choose the artist with the largest number of remaining unplayed songs. If multiple artists are tied, choose the one whose first song appears earliest in the original playlist . (This position is fixed — it is the index at which the artist first occurs in the input, and it does not change as songs are played.) Do not choose the same artist as the previously played song, unless no other artist has any songs left. For songs by the same artist, preserve their original relative order from the input playlist. Return the reordered list of [title, artist] pairs representing the play order. Input Format The first line contains the integer n , the number of inner arrays in playlist[] . The next line contains the integer 2 , the number of elements in each inner array. The next n lines contain two space-separated strings represent