Minimum Piano Hand Raises and Thumb Positions
Problem statement
For this exercise, assume a piano keyboard has keys numbered 0 through 87. One hand placement puts the thumb on some key p and covers the five consecutive keys p through p + 4, one per finger: finger 0 (the thumb) on p up to finger 4 (the little finger) on p + 4.
Play the notes in their given order. The first hand placement is free, and each move to another placement is one hand raise. Find the minimum number of raises.
Examples
Example 1
notes = [0,4,5,9,10]return = [2,0,5,10]The longest fitting segments are [0, 4], [5, 9] and [10]. Their lowest notes are 0, 5 and 10, so those are the thumb positions. Three placements need two raises. In the first segment, note 4 is played by finger 4 - 0 = 4.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 2 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.