FastPrepMinimum Cost of Left and Right Propagation
Problems/Minimum Cost of Left and Right Propagation

Minimum Cost of Left and Right Propagation

Amazon logoAmazon● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Amazon intern online assessment. We set the limits so values are positive. One sample result that someone remembered does not fit the stated operation costs. Our version follows those costs and allows repeated operations. It is about 95% the same as the reported question.

Special thanks: 🌷 A special thank you to our lovely, amazing frenz for sharing this question and similar interview variations, with reported dates of October 2, 2026, October 15, 2026, November 2, 2026, and November 17, 2026! ( ˘͈ ᵕ ˘͈♡) 🩷

You are given a positive integer array values. You may perform either propagation operation any number of times and in any order:

  • Choose index i and propagate left: replace every element before i with values[i]. This costs i * values[i].
  • Choose index i and propagate right: replace every element after i with values[i]. This costs (n - 1 - i) * values[i].

Return the minimum total cost needed to make every array element equal. You may perform zero operations when the array is already uniform.

Function

minimumPropagationCost(values: int[]) → long

Examples

Example 1

values = [5,2,4]return = 4

Keep the middle value 2, propagate it left for cost 2, and propagate it right for another cost 2.

Example 2

values = [1,1,2,1]return = 2

Keep the first run of two 1s and propagate right from index 1 for cost 2.

Example 3

values = [5,1,1,2,1,1]return = 4

Keep the run of two 1s at indices 1 and 2. Propagate left from index 1 for cost 1, then right from index 2 for cost 3. The total is 4; no original equal-value run gives a lower cost.

Constraints

  • 1 <= values.length <= 100000
  • 1 <= values[i] <= 10^9
  • The answer fits in a signed 64-bit integer.

More Amazon Online Assessment questions

  • Lexicographically Largest IdentifierOA · Seen Nov 2026
  • Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
  • Top K Frequent ElementsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Fill One Exact-Length Binary WindowOA · Seen Nov 2026
  • Minimum Grid InconvenienceOA · Seen Nov 2026
  • Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
  • Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Get Smallest Base SegmentOA · Seen Nov 2026
  • Maximum Equal-Bit Pairs in a SubsequenceOA · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Earn the Most 🐝Capital One · OA
  • Minimum Cost to Merge Values into OnePayPal · OA
  • Minimum Operations to Sort with Rotations Then SwapsBank of New York Mellon · OA
  • Minimum Rounds to Complete All TasksInfosys · OA
  • Reschedule Meetings for Maximum Free TimeFivetran · OA
  • Maximum Easy Tasks After RearrangingIBM · OA
  • Minimum Cost K-Capable ModelsMicrosoft · OA
  • Maximum ScoreNVIDIA · OA
  • Maximum Distinct Values After Unit AdjustmentsBirla Pivot · OA
  • Minimize Adjacent Squared-Difference Cost with One InsertionMcKinsey & Company · OA
See Amazon hiring insights
Saved
class Solution {
    public long minimumPropagationCost(int[] values) {
        // Write your code here.
    }
}
Checking account…