FastPrepMinimum Pile Reduction Steps
Problems/Minimum Pile Reduction Steps

Minimum Pile Reduction Steps

American Express logoAmerican Express● EasyFULLTIMEOA

Updated Aug 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The original report specifies repeatedly lowering a highest pile to the next distinct height and gives the result 3 for [5,2,1]. It does not explicitly define whether one or all highest piles change per step. This practice version changes one pile per step, which preserves the reported result.

You are given a nonempty array heights, where each value is the height of one pile.

In one step, choose one pile whose height is currently maximal and lower that pile to the greatest strictly smaller height currently present among the piles.

Return the minimum number of steps needed to make every pile have the same height.

Function

minimumPileReductionSteps(heights: int[]) → long

Examples

Example 1

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

Lower 5 to 2 in one step, then lower each of the two piles of height 2 to 1. The total is 3 steps.

Example 2

heights = [4,4,4]return = 0

All piles already have the same height.

Example 3

heights = [10,10,5,5,1]return = 6

The two piles of height 10 take two steps to reach 5. The four piles then at height 5 take four more steps to reach 1.

Constraints

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

More American Express interview questions

  • Maximum Points in a Perimeter-Bounded RectangleOA · Seen Sep 2026
  • Minimum Moves to Spread Stones Across a GridOA · Seen Sep 2026
  • Largest Two Non-Overlapping Buildable SquaresOA · Seen Aug 2026
  • Maximum Sum of Two Sign-Flipping WindowsOA · Seen Aug 2026
  • Crop Text at a Whole-Word BoundaryOA · Seen Aug 2026
  • Minimum Parking Roof LengthOA · Seen Aug 2026
  • Disjoint Target-Sum TripletsPHONE SCREEN · Seen Mar 2025

Similar questions at other companies

  • Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OA
  • Maximum Apples That Fit in a BoxVirtu Financial · OA
  • Server ManagementRippling · OA
  • Maximum Three-Server Difficulty ScoreVisa · OA
  • Economical TripAccenture · OA
  • Find Maximum Number of Subjects Passed (AS Intern, but it may apply to other interns) 🍋Amazon · OA
  • Maximum Production Within PowerZomato / Eternal · OA
  • Can Every Package Fit in a BoxIMC Trading · OA
  • Compute Walking DistanceTikTok · OA
  • Minimum Tunnel Crossing TimeArcesium · OA
See American Express hiring insights
Saved
class Solution {
    public long minimumPileReductionSteps(int[] heights) {
        // Write your code here.
    }
}
Checking account…