FastPrepMinimum Piano Hand Raises and Thumb Positions

Minimum Piano Hand Raises and Thumb Positions

Google logoGoogle● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW

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.

The problem statement continues
Pro

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.

FastPrep Pro
Reported in 1 Google interview this week

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
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week
See Google hiring insights
CodePython 3
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Google interview this week

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
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week