FastPrepCan the Singer Perform the Song?

Can the Singer Perform the Song?

Walmart logoWalmart● EasyFULLTIMEPHONE SCREEN
Learn

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) → boolean

Examples

Example 1

song = ["F4","B4","C5"]lowest = "F4"highest = "C5"return = true

Every song note lies within the inclusive range.

Example 2

song = ["F4","B4","C5"]lowest = "A4"highest = "C5"return = false

At least one song note is outside the inclusive range.

Constraints

  • For this exercise, assume 0 <= song.length <= 1000.
  • Each note is exactly one letter from CDEFGAB followed by one digit from 0 through 7.
  • lowest is no higher than highest.

More Walmart problems

See Walmart hiring insights
public boolean singable(String[] song, String lowest, String highest) {
    // Write your code here.
    return false;
}
song["F4","B4","C5"]
lowest"F4"
highest"C5"
expectedtrue
Checking account…