Problem · Array
Get Minimum Increment
Learn this problemProblem statement
Given an integer array arr of length n, you can perform the following operation on the array at most once:
x, and increase all the selected elements by x.
Determine the minimum non-negative integer x, required to make the array arr non-decreasing using at most one operation. If it is impossible, return -1.
Function
getMinimumIncrement(arr: int[]) → int
Complete the function getMinimumIncrement in the editor with the following parameter(s):
int arr[n]: the array
Returns
int: the minimum value of increment so that the array becomes non-decreasing
Examples
Example 1
arr = [1, 1, 3, 2]return = 1Some of the possible ways are:
- Select the element with index 3 (0-based indexing) and increment = 1 to get the array
arr = [1, 1, 3, 3]. - Select the elements with indices [1, 3] (0-based indexing) and increment = 2 to get the array
arr = [1, 3, 3, 4].
More IBM problems
- Parent Process NumberOA · Seen Jul 2026
- Request Retry CountOA · Seen Jul 2026
- Count Strictly Increasing Subsequences of Length 3OA · Seen Jul 2026
- Maximum Requests in a Time WindowOA · Seen Jul 2026
- Query Type Frequency WindowOA · Seen Jul 2026
- Minimum Number of Non-Empty Disjoint SegmentsOA · Seen Jul 2026
- Spam Text ClassificationOA · Seen Jul 2026
- Count Ideal NumbersOA · Seen Jun 2026