PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Amazon

Implement two array-cost minimization algorithms

Last updated: Mar 29, 2026

Quick Overview

This question evaluates algorithm design, data structure selection, and complexity analysis by requiring implementations for minimizing total merge cost and for removing a contiguous block to minimize the sum of adjacent absolute differences.

  • Medium
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Implement two array-cost minimization algorithms

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Onsite

Implement two array-cost minimization algorithms. 1) Minimize merge cost: Given a list of positive integers workloads representing task sizes, you may repeatedly merge any two items a and b into a single item of size a+b, incurring cost a+b for that merge. Implement minimizeSystemCost(workloads: int[]) -> long that returns the minimal total cost to end with one item. State the algorithm and its time/space complexity. 2) Remove a contiguous block: Given an integer array machines representing machine strengths and an integer k (1 <= k < machines.length), remove exactly k consecutive elements so that, for the remaining sequence in original order, the sum over all adjacent pairs of |strength[i] - strength[i+1]| is minimized. Implement minimizeRemainingAdjDiff(machines: int[], k: int) -> (long minCost, int startIndex), returning the minimal cost and a valid starting index of the removed block. Target O(n) or O(n log n).

Quick Answer: This question evaluates algorithm design, data structure selection, and complexity analysis by requiring implementations for minimizing total merge cost and for removing a contiguous block to minimize the sum of adjacent absolute differences.

Related Interview Questions

  • Implement Datacenter Router Commands - Amazon (hard)
  • Replace Delimited Tokens in a String - Amazon (medium)
  • Minimize Circular Redistribution Cost - Amazon (medium)
  • Find the Most Common Visit Pattern - Amazon (hard)
  • Maximize Value Under a Budget - Amazon (medium)
Amazon logo
Amazon
Aug 7, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
2
0

Implement two array-cost minimization algorithms.

  1. Minimize merge cost: Given a list of positive integers workloads representing task sizes, you may repeatedly merge any two items a and b into a single item of size a+b, incurring cost a+b for that merge. Implement minimizeSystemCost(workloads: int[]) -> long that returns the minimal total cost to end with one item. State the algorithm and its time/space complexity.
  2. Remove a contiguous block: Given an integer array machines representing machine strengths and an integer k (1 <= k < machines.length), remove exactly k consecutive elements so that, for the remaining sequence in original order, the sum over all adjacent pairs of |strength[i] - strength[i+1]| is minimized. Implement minimizeRemainingAdjDiff(machines: int[], k: int) -> (long minCost, int startIndex), returning the minimal cost and a valid starting index of the removed block. Target O(n) or O(n log n).

Submit Your Answer

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,500+ 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.