Company: Flipkart Grid 8.0
Difficulty: medium
Akash loves listening to music while jogging and wants to set up a new regime for his jogging with an app named Jog Track on his new iPod. He plans to complete his workout based on the playlist time. Initially he sets an expected workout time D for the jog. Then he chooses a playlist of N entries. Every entry is a pair (Si, Ti) , where Si is the song ID and Ti is the time value recorded for that entry. A song may get repeated in the playlist, because he is obsessed with some of the songs. He now needs to find his actual workout time Z for the day. The following algorithm calculates Z : Step 1 — Add up all the Ti values of the playlist to get a sum X . Step 2 — Multiply X by the number of unique songs in the playlist (duplicates removed) to get Y . Step 3 — Take the unique songs and sort them in descending order of their corresponding time T . If a song occurs more than once in the playlist, the value used for it is the lowest T among its occurrences. The sorted songs are given sequence