Algorithm · Amazon · Hard
You are given an integer array arr of length n. In one operation, you may pick any element and decrement it by 1. Your goal is to turn the array into a bitonic array using the fewest operations possible. A bitonic array is defined as follows: It can have a prefix and/or suffix made entirely of zeros. The non-zero portion must strictly ascend from 1 up to a peak value k, and then strictly descend back down to 1. For instance, [0, 1, 2, 3, 2, 1, 0, 0] is a valid bitonic array.…
Checking your access…