Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imagine you're a beginner piano player and you use only your right hand. You can reach five keys without moving your hand,
- the key your thumb is on and the four keys to the right of it.
- The piano keys are numbered sequentially from left to right, starting with the leftmost key as note 1.
- You'll receive a list of notes representing a simple piano piece, and your objective is to play the entire piece
- while minimizing the number of times you need to reposition your hand.
- How many times would you need to move your hand to play the whole song?
- // Has to be played in the given order.
- Example 1
- Input: [1, 2, 3, 4, 5, 4, 3, 2, 1]
- Answer: 0. If you play your thumb on note 1, the whole piece can be played without a move.
- Example 2
- Input: [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
- Answer: 1. Place your thumb on 6 and play [10, 9, 8, 7, 6]. Then, reposition your thumb to note 1 and play the rest.
- Input: [6, 5, 4, 3, 2, 7, 8 ,9, 10]
- Answer: 1. Place your thumb on 2 and then on 7,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement