FastPrepMinimum Increments for Stepwise Towers
Problems/Minimum Increments for Stepwise Towers

Minimum Increments for Stepwise Towers

ZipRecruiter logoZipRecruiter● MediumNEW GRADFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Five ZipRecruiter OA reports describe moves that only increment, and the choice between consecutive increasing and decreasing targets. The reports leave out numeric limits and a function signature, so our version supplies those details.

You are given an integer array towers, where towers[i] is the height of the ith tower.

In one move, add exactly one block to any tower. Blocks cannot be removed.

Make the entire sequence stepwise in either direction:

  • increasing: every height is exactly one greater than the previous height; or
  • decreasing: every height is exactly one less than the previous height.

Return the minimum number of moves required.

Function

minimumStepwiseIncrements(towers: int[]) → long

Examples

Example 1

towers = [1,4,3,2]return = 4

Raise the first tower from 1 to 5. The result [5,4,3,2] is stepwise decreasing and costs four moves.

Example 2

towers = [5,7,9,4,11]return = 9

The cheapest target is [7,8,9,10,11], requiring 2 + 1 + 0 + 6 + 0 = 9 added blocks.

Constraints

  • 1 <= towers.length <= 100000
  • 0 <= towers[i] <= 1000000000
  • The answer fits in a signed 64-bit integer.

More ZipRecruiter Online Assessment questions

  • Four-Level Banking System with Scheduled PaymentsOA · Seen Oct 2026
  • Count Three-Digit Numbers with Distinct DigitsOA · Seen Oct 2024
  • Longest Frequency-Bounded SubarrayOA · Seen Oct 2024
  • Minimum Changes to Draw a YOA · Seen Oct 2024
  • Apply Binary State OperationsOA · Seen Sep 2024
  • Simulate Orchard Rot SpreadOA · Seen Sep 2024
  • Compare Odd- and Even-Index SumsOA · Seen Sep 2024
  • Coordinate Removals with Column GravityOA · Seen Sep 2024
  • Lexicographically Smallest End ReversalOA · Seen Sep 2024
  • Recursively Expanded Shell Command CountsOA · Seen Sep 2024

Similar questions at other companies

  • Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
  • Minimize Adjacent Squared-Difference Cost with One InsertionMcKinsey & Company · OAMcKinsey & Company interview questions
  • Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
  • Minimum Values with Even Powers of TwoVisa · OAVisa interview questions
  • Minimize Adjacent Squared-Difference Cost with One InsertionMicrosoft · OAMicrosoft interview questions
  • Minimum Halvings for Alternating ParityIBM · OAIBM interview questions
  • Resource AllocationMaven Securities · OAMaven Securities interview questions
  • Rock JumpingIMC Trading · OAIMC Trading interview questions
  • Minimum Total Batch ExpenseAmazon · OA
  • Coprime Pick with Change CostCitadel · OACitadel interview questions

ZipRecruiter interview experiences

  • ZipRecruiter SWE OA, Level Not Reported: 23 Experiences
  • ZipRecruiter SWE Intern OA Scores: 4 Experiences
  • ZipRecruiter SWE New Grad OA: 9 Experiences
All ZipRecruiter interview questionsSee ZipRecruiter hiring insights
Saved
class Solution {
    public long minimumStepwiseIncrements(int[] towers) {
        // Write your code here.
    }

}
Checking account…