Can the Singer Perform the Song?
Problem statement
A singer can perform a song only when every note is within the singer's inclusive vocal range. Given song, lowest, and highest, return whether the singer can perform the song.
Each note contains a pitch letter followed by one octave digit. Pitches increase in the order C, D, E, F, G, A, B; octaves increase from 0 through 7. A note in a higher octave is always higher than any note in a lower octave. Within one octave, compare pitch order.
For example, G3 < A3 < B3 < C4 < D4. The lowest possible note is C0, and the highest is B7.
For this exercise, assume all notes and vocal endpoints are valid, lowest is no higher than highest, and an empty song is singable.
Function
singable(song: String[], lowest: String, highest: String) → booleanExamples
Example 1
song = ["F4","B4","C5"]lowest = "F4"highest = "C5"return = trueEvery song note lies within the inclusive range.
Example 2
song = ["F4","B4","C5"]lowest = "A4"highest = "C5"return = falseAt least one song note is outside the inclusive range.
Example 3
song = ["C3","E3","G3","C4","E4","G4","C5"]lowest = "B2"highest = "C5"return = trueEvery song note lies within the inclusive range.
Example 4
song = ["C3","E3","G3","C4","E4","G4","C5"]lowest = "C3"highest = "B4"return = falseAt least one song note is outside the inclusive range.
Example 5
song = ["B4","F5","B5"]lowest = "B4"highest = "B5"return = trueEvery song note lies within the inclusive range.
Example 6
song = ["B4","F5","B5"]lowest = "B4"highest = "C5"return = falseAt least one song note is outside the inclusive range.
Example 7
song = ["B4","E4","G4","G4","A4","B4","E4","B4","E4","G4","G4","A4","C5","B4","E5","G4","G4","A4","B4","C5","D5","C5","B4","C5","E5","D5","C5","C5","B4","B4","E5","E4","G4","G4","A4","B4","B4","B4","C5","E5","A5","E5","C5","A4","E5","D5","C5","B4"]lowest = "D4"highest = "A5"return = trueEvery song note lies within the inclusive range.
Example 8
song = ["B4","E4","G4","G4","A4","B4","E4","B4","E4","G4","G4","A4","C5","B4","E5","G4","G4","A4","B4","C5","D5","C5","B4","C5","E5","D5","C5","C5","B4","B4","E5","E4","G4","G4","A4","B4","B4","B4","C5","E5","A5","E5","C5","A4","E5","D5","C5","B4"]lowest = "D4"highest = "G5"return = falseAt least one song note is outside the inclusive range.
Example 9
song = ["B4","E4","G4","G4","A4","B4","E4","B4","E4","G4","G4","A4","C5","B4","E5","G4","G4","A4","B4","C5","D5","C5","B4","C5","E5","D5","C5","C5","B4","B4","E5","E4","G4","G4","A4","B4","B4","B4","C5","E5","A5","E5","C5","A4","E5","D5","C5","B4"]lowest = "D4"highest = "C6"return = trueEvery song note lies within the inclusive range.
Example 10
song = ["B4","E4","G4","G4","A4","B4","E4","B4","E4","G4","G4","A4","C5","B4","E5","G4","G4","A4","B4","C5","D5","C5","B4","C5","E5","D5","C5","C5","B4","B4","E5","E4","G4","G4","A4","B4","B4","B4","C5","E5","A5","E5","C5","A4","E5","D5","C5","B4"]lowest = "F4"highest = "C6"return = falseAt least one song note is outside the inclusive range.
Example 11
song = ["F4"]lowest = "D4"highest = "E4"return = falseAt least one song note is outside the inclusive range.
Constraints
- For this exercise, assume
0 <= song.length <= 10^4. - Each note is exactly one letter from
CDEFGABfollowed by one digit from0through7. lowestis no higher thanhighest.