Setlist key totals
EasyOnline Assessment
Total the playing time of a band's setlist for each musical key.
Each entry of songs has the form "title|key|m:ss": the song's title, the key it is played in, and its length in minutes and seconds. Spaces around the title and the key should be ignored.
- A song listed more than once counts only the first time. Titles are compared ignoring case and surrounding spaces, and a later copy is ignored completely, even if it names a different key or length.
- A key is a note letter
AtoG, an optional#orb, and an optionalmfor minor.CandCmare different keys. Enharmonic spellings are the same key:C#/Db,D#/Eb,F#/Gb,G#/AbandA#/Bb(and likewise with a trailingm). Whenever two spellings meet, the key is reported with the spelling used by its first counted song. - A key's total is the sum of its song lengths. Minutes do not roll over into hours: three songs of
40:00make120:00.
Input: songs, a list of strings in the format above.
Output: a list of [key, total] pairs, where total is a string "m:ss" (seconds always two digits). Sort by total time, longest first; keys with equal totals are ordered by key in plain character order (so "A" < "A#" < "Am"). Return [] for an empty setlist.
Example 1
- Input:
- [["Sunrise|Am|3:45","Harbor Lights|C|4:10","Static|Am|2:30","Low Tide|Em|5:00"]]
- Output:
- [["Am","6:15"],["Em","5:00"],["C","4:10"]]
- Explanation
- Am has two songs: 3:45 + 2:30 = 6:15. Em has 5:00 and C has 4:10. Sorted by total time, longest first.
Example 2
- Input:
- [["Ember|C#|3:50","Glass|Db|4:20","Hush|C#m|1:05","Tin|Db|0:55"]]
- Output:
- [["C#","9:05"],["C#m","1:05"]]
- Explanation
- C# and Db are the same key, so 3:50 + 4:20 + 0:55 = 9:05, shown as C# because the first counted song used that spelling. C#m is a different (minor) key, with 1:05.
Example 3
- Input:
- [["Opener|G|10:30","opener |D|3:00","Closer|D|25:45","Jam|G|40:00","Jam |A|1:00"," Reprise|D|50:30","Coda|B|50:30"]]
- Output:
- [["D","76:15"],["B","50:30"],["G","50:30"]]
- Explanation
- The second "opener" and the second "Jam" are repeats of earlier titles and are ignored completely (so the 3:00 in D and the 1:00 in A never count). D = 25:45 + 50:30 = 76:15. G = 10:30 + 40:00 = 50:30 ties with B = 50:30, and B comes first in character order.
Constraints
0 <= songs.length <= 1,000- Each entry is
"title|key|m:ss";titlehas letters, digits and spaces;keyis a letterA-Gfollowed by an optional#orb, then an optionalm(minor);mis between 0 and 99 andssis two digits between 00 and 59 - Titles and keys may carry extra leading or trailing spaces