Company: Eternal (Zomato)_SDE Intern_Oncampus_25july
Difficulty: medium
You are given a playlist of n songs. Song i has a title and an artist. You want to build a new play order by repeatedly selecting songs, one at a time, according to the following rule. At each step, consider all artists who still have at least one unplayed song, excluding the artist of the song you played in the immediately previous step . Among those artists: 1. Choose the artist with the largest number of remaining unplayed songs. 2. If several artists are tied for the largest number of remaining songs, choose the artist whose first song (the earliest position in the original playlist) appears earliest. From the chosen artist, play their earliest unplayed song (the one at the smallest original position). The very first selection has no "previous artist" restriction. Stop when no artist can be selected — that is, when there are no unplayed songs left, or the only artist with unplayed songs is the one whose song you just played. Any songs that remain unplayed when you stop ar