Can the Singer Perform the Song?
Updated
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.
Constraints
- For this exercise, assume
0 <= song.length <= 1000. - Each note is exactly one letter from
CDEFGABfollowed by one digit from0through7. lowestis no higher thanhighest.
More Walmart Phone Screen questions
- Count Months Starting on SundayPHONE SCREEN · Seen Aug 2026
- Longest Even-Length WordPHONE SCREEN · Seen Aug 2026
- Range ModulePHONE SCREEN · Seen Aug 2026
- Meeting Rooms IIPHONE SCREEN · Seen Aug 2026
- Sort Real Number StringsPHONE SCREEN · Seen Jan 2026
- Check a Password Against a Supplied PolicyPHONE SCREEN · Seen Jun 2025
- Convert a Restricted Function to an Arrow FunctionPHONE SCREEN · Seen Jun 2025
- Repair One Missing Function Punctuation CharacterPHONE SCREEN · Seen Jun 2025
- Rooms With Two Other Entrances and a Treasure SuccessorPHONE SCREEN · Seen Mar 2025
- First Dictionary Word from Note LettersPHONE SCREEN · Seen Aug 2022
Similar questions at other companies
- Search and Format ContactsAdyen · PHONE SCREENAdyen interview questions
- Detect a Straight FlushTemu · PHONE SCREENTemu interview questions
- Longest Common PrefixKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Single-Condition Product FilterCrowdstrike · PHONE SCREENCrowdstrike interview questions
- Match a Variadic Function SignatureConfluent · PHONE SCREENConfluent interview questions
- Parse and Sort Integer DataLegora · PHONE SCREEN
- Convert an Entry List to a MapEPAM · PHONE SCREENEPAM interview questions
- Longest All-Present Attendance StreakOracle · PHONE SCREENOracle interview questions
- Most Frequent NameAmazon · PHONE SCREEN