FastPrepMake Array Bitonic
Problems/Make Array Bitonic

Make Array Bitonic

Amazon logoAmazon● HardOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given an array arr of n integers. In one operation you can lower any element by 1. Return the minimum number of operations needed to make arr bitonic.

In this problem, a bitonic array may start and end with any number of zeros. The non-zero part in the middle must go up by 1 at a time from 1 to some peak k, then down by 1 at a time back to 1. For example, [0, 1, 2, 3, 2, 1, 0, 0] is bitonic.

Function

minOperationsToMakeBitonic(arr: int[]) → int

Examples

Example 1

arr = [3,3,3,3,3]return = 6

Lower the array to [1, 2, 3, 2, 1]. That takes 2 + 1 + 0 + 1 + 2 = 6 operations, the fewest possible.

Example 2

arr = [1,1,3,1,1]return = 3

Lower the array to [0, 1, 2, 1, 0]. That takes 1 + 0 + 1 + 0 + 1 = 3 operations. A peak of 3 in the middle would need [1, 2, 3, 2, 1], but the second element is only 1 and can never go up.

Example 3

arr = [1,2,1,3,2]return = 5

Lower the array to [1, 2, 1, 0, 0] (or to [0, 0, 1, 2, 1]). Either way 4 of the total 9 stays, so 9 - 4 = 5 operations.

Constraints

  • 1 ≤ n ≤ 10^5, where n is the length of arr
  • 1 ≤ arr[i] ≤ 10^4

More Amazon interview questions

  • Next Greater Element IONSITE INTERVIEW · Seen Dec 2026
  • Count Connected ComponentsPHONE SCREEN · Seen Dec 2026
  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Merge Accounts by Shared AttributePHONE SCREEN · Seen Dec 2026
  • Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Minimum Grid InconvenienceOA · Seen Dec 2026
  • Optimal Account BalancingONSITE INTERVIEW · Seen Dec 2026
  • Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Flood FillONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • At Most K Jumps with Quadratic Transition CostInfosys · OAInfosys interview questions
  • Largest Consistent Visiting GroupAuxoAI · OA
  • Delete K Subsets for Maximum ScoreRubrik · OARubrik interview questions
  • Optimize Discount Selection Under a Point BudgetPalantir · OAPalantir interview questions
  • Maximum Index-Weighted Sum with Disjoint SwapsVisa · OAVisa interview questions
  • Maximum Sum of HeightsVirtu Financial · OAVirtu Financial interview questions
  • Pressure-Isolation Shutdown OrderIntuit · OAIntuit interview questions
  • Get Minimum IncrementIBM · OAIBM interview questions
  • Jump Game with Prime-3 StepsUber · OAUber interview questions
  • Maximum Payout with Context SwitchesPhonePe · OAPhonePe interview questions

Interview reports that mention this question

  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
  • Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)
See Amazon hiring insights
Saved
class Solution {
    public int minOperationsToMakeBitonic(int[] arr) {
      // write your code here
    }

}
Checking account…