FastPrepGet Minimum Increment
Problems/Get Minimum Increment

Get Minimum Increment

IBM logoIBM● HardFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamples

Problem statement

Given an integer array arr of length n, you can perform the following operation on the array at most once:

  • Choose a subset of elements from the array such that no two selected elements are adjacent (i.e., no two selected elements are next to each other in the array).
  • Choose a non-negative integer 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 = 1

Some 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].

Hence, the minimum value of increment is 1.

More IBM interview questions

  • Count Strictly Increasing Contiguous WindowsOA · Seen Nov 2026
  • Total Each Letter's Count in an Encoded StringOA · Seen Nov 2026
  • Count Servers With No Requests in a Time WindowOA · Seen Nov 2026
  • Alternate Odd and Even Numbers with Two GoroutinesPHONE SCREEN · Seen Nov 2026
  • Longest Substring Without Repeating CharactersPHONE SCREEN · Seen Nov 2026
  • Maximum Easy Tasks After RearrangingOA · Seen Nov 2026
  • Longest Palindromic SubstringPHONE SCREEN · Seen Oct 2026
  • Merge Two Sorted ListsPHONE SCREEN · Seen Oct 2026
  • Reverse a Linked ListPHONE SCREEN · Seen Oct 2026
  • Tree Pythagorean TriplesOA · Seen Oct 2026

Similar questions at other companies

  • Split Array to Minimize the Largest SumInfosys · OAInfosys interview questions
  • Split Array Largest SumAuxoAI · OA
  • Minimum Number of Taps to Water a GardenGoldman Sachs · OAGoldman Sachs interview questions
  • Find Minimum Cost to Shift MachinesCisco · OACisco interview questions
  • Maximum Income from Asset TradingJefferies · OA
  • Best Time to Buy and Sell StockFlexTrade · OAFlexTrade interview questions
  • Maximum Even-Sum Neighboring PairsDRW · OADRW interview questions
  • Minimize Total Input Cost (for LTMS)Salesforce · OASalesforce interview questions
  • Maximize Protected City PopulationAmazon · OA
  • Network FormationPalantir · OAPalantir interview questions

IBM interview experiences

  • IBM Software Intern Résumé Rounds: 2 Experiences (Part 3 of 3)
  • IBM Intern Blitz Interviews: 23 Experiences (Part 2 of 3)
  • IBM Software Intern Interviews: 44 Experiences (Part 1 of 3)
  • IBM Software Intern Interview Questions: 15 Experiences
All IBM interview questionsSee IBM hiring insights
Saved
class Solution {
    public int getMinimumIncrement(int[] arr) {
      // write your code here
    }

}
Checking account…