PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Amazon

Find minimum total range-increment to sort

Last updated: Mar 29, 2026

Quick Overview

This question evaluates algorithmic problem-solving skills in array manipulation and optimization, focusing on reasoning about range-increment operations, cost minimization, and preserving non-decreasing order.

  • medium
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Find minimum total range-increment to sort

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

You are given an integer array `power[0..n-1]` representing computational power of `n` servers. You may perform the following operation any number of times: - Choose a **contiguous segment** `[l, r]` (0-indexed, `0 <= l <= r < n`) - Choose an integer `x >= 0` - Increase every element in that segment by `x` (i.e., for all `i in [l, r]`, set `power[i] += x`) Your goal is to make the final array **non-decreasing** (i.e., `power[i] <= power[i+1]` for all valid `i`). Let the “cost” be the **sum of all chosen `x` values** across all operations (segment length does not affect cost). Compute the **minimum possible cost**. Example: - `n = 5`, `power = [3, 4, 1, 6, 2]` - One optimal sequence: - add `3` to subarray `[2, 4]` → `[3, 4, 4, 9, 5]` - add `4` to subarray `[4, 4]` → `[3, 4, 4, 9, 9]` - Minimum cost = `3 + 4 = 7` Complete the function: - `findMinimumSum(power)` → returns an integer: the minimum achievable total cost. Assumptions: - `power[i]` are integers; only increases are allowed (`x >= 0`).

Quick Answer: This question evaluates algorithmic problem-solving skills in array manipulation and optimization, focusing on reasoning about range-increment operations, cost minimization, and preserving non-decreasing order.

Related Interview Questions

  • Implement Datacenter Router Commands - Amazon (hard)
  • Implement Event Filtering and Queue Routing - Amazon (medium)
  • Determine if all courses can be completed - Amazon (medium)
  • Replace Delimited Tokens in a String - Amazon (medium)
  • Minimize Circular Redistribution Cost - Amazon (medium)
Amazon logo
Amazon
Jan 6, 2026, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
5
0
Loading...

You are given an integer array power[0..n-1] representing computational power of n servers.

You may perform the following operation any number of times:

  • Choose a contiguous segment [l, r] (0-indexed, 0 <= l <= r < n )
  • Choose an integer x >= 0
  • Increase every element in that segment by x (i.e., for all i in [l, r] , set power[i] += x )

Your goal is to make the final array non-decreasing (i.e., power[i] <= power[i+1] for all valid i).

Let the “cost” be the sum of all chosen x values across all operations (segment length does not affect cost). Compute the minimum possible cost.

Example:

  • n = 5 , power = [3, 4, 1, 6, 2]
  • One optimal sequence:
    • add 3 to subarray [2, 4] → [3, 4, 4, 9, 5]
    • add 4 to subarray [4, 4] → [3, 4, 4, 9, 9]
  • Minimum cost = 3 + 4 = 7

Complete the function:

  • findMinimumSum(power) → returns an integer: the minimum achievable total cost.

Assumptions:

  • power[i] are integers; only increases are allowed ( x >= 0 ).

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Amazon•More Software Engineer•Amazon Software Engineer•Amazon Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.