Minimum Pile Reduction Steps
Updated
Problem statement
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[]) → longExamples
Example 1
heights = [5,2,1]return = 3Lower 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 = 0All piles already have the same height.
Example 3
heights = [10,10,5,5,1]return = 6The 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 <= 1000001 <= 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