Advertisement
Guest User

Untitled

a guest
Apr 30th, 2025
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. Imagine you're a beginner piano player and you use only your right hand. You can reach five keys without moving your hand,
  2. the key your thumb is on and the four keys to the right of it.
  3.  
  4. The piano keys are numbered sequentially from left to right, starting with the leftmost key as note 1.
  5. You'll receive a list of notes representing a simple piano piece, and your objective is to play the entire piece
  6. while minimizing the number of times you need to reposition your hand.
  7.  
  8. How many times would you need to move your hand to play the whole song?
  9.  
  10.  
  11.  
  12. // Has to be played in the given order.
  13.  
  14. Example 1
  15.  
  16. Input: [1, 2, 3, 4, 5, 4, 3, 2, 1]
  17. Answer: 0. If you play your thumb on note 1, the whole piece can be played without a move.
  18. Example 2
  19.  
  20. Input: [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
  21. 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.
  22.  
  23. Input: [6, 5, 4, 3, 2, 7, 8 ,9, 10]
  24. Answer: 1. Place your thumb on 2 and then on 7,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement