Save 25%Black Friday: 25% off all plans — use code BLACKFRIDAY2026 at checkout. Ends Friday, Dec 4.Claim the deal

Given an array arr, where each element represents the distance you can fly on the ithi^{\text{th}} day. You start with k units of energy, which is also your maximum energy capacity. Each day, you can either:

  • Fly: Use 1 unit of energy to fly arr[i] distance.
  • Rest: Recover 1 unit of energy, up to the maximum of k.
Test Cases
Input
Output
Expected