Algorithm · PayPal · Hard
You are given an integer array arr. Modifying any element costs the absolute difference between its current value and the new value you assign. For instance, turning a 10 into either 7 or 13 incurs a cost of 3. Your goal is to transform the array so that it follows one consistent order from left to right — either each element is greater than or equal to the previous one (non‑decreasing, i.e., ascending) or each element is less than or equal to the previous one…
Checking your access…