FastPrepConnect N Ropes With Minimum Cost
Problems/Connect N Ropes With Minimum Cost

Connect N Ropes With Minimum Cost

Amazon logoAmazon● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Amazon full-time onsite interview. The report names a well-known problem. We chose the function signature, a fixed order for the output, and the input limits. Our version is about 98% the same as the reported question.

You are given an integer array ropes, where ropes[i] is the length of one rope.

In one operation, choose any two ropes, connect them into one rope, and pay a cost equal to the sum of their lengths. The new rope has that same combined length.

Return the minimum total cost required to connect all ropes into one rope. If there is only one rope, return 0.

Function

minimumRopeConnectionCost(ropes: int[]) → long

Examples

Example 1

ropes = [4,3,2,6]return = 29

Connect lengths 2 and 3 for cost 5, then 4 and 5 for cost 9, and finally 6 and 9 for cost 15. The total is 5 + 9 + 15 = 29.

Example 2

ropes = [4,2,7,6,9]return = 62

One optimal sequence has merge costs 6, 12, 16, and 28, for a total of 62.

Example 3

ropes = [10]return = 0

Only one rope is present, so no connection operation is needed.

Constraints

  • 1 <= ropes.length <= 10^5
  • 1 <= ropes[i] <= 10^4
  • The result fits in a signed 64-bit integer.

Source note: Author-written prompt excerpt retained for source fidelity.

More Amazon Onsite Interview questions

  • Next Greater Element IONSITE INTERVIEW · Seen Dec 2026
  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Optimal Account BalancingONSITE INTERVIEW · Seen Dec 2026
  • Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Flood FillONSITE INTERVIEW · Seen Nov 2026
  • Merge k Sorted ListsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Assign Escalations to TeamsONSITE INTERVIEW · Seen Nov 2026
  • Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
  • API Call Thread Pool ScheduleBaseten · ONSITE INTERVIEWBaseten interview questions
  • Minimum Workers with Job AssignmentsLyft · ONSITE INTERVIEWLyft interview questions
  • Ad Rotation Scheduler With CooldownGoogle · ONSITE INTERVIEWGoogle interview questions
  • Most Transactions Kept Without Going NegativeDocuSign · ONSITE INTERVIEWDocuSign interview questions
  • Maximum Supplier ProfitExpedia · ONSITE INTERVIEWExpedia interview questions
  • Minimum Stick Connection CostNavan · ONSITE INTERVIEWNavan interview questions
  • Movie Schedule for Maximum EnjoymentC3.ai · ONSITE INTERVIEWC3.ai interview questions
  • Allocate Customers to Preferred SitesYelp · ONSITE INTERVIEWYelp interview questions
  • Greedy and Beam Sentence DecodingMicrosoft · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions

Interview reports that mention this question

  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II (L5) Interview Questions: 5 Experiences

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
See Amazon hiring insights
Saved
class Solution {
    public long minimumRopeConnectionCost(int[] ropes) {
      // write your code here.
    }
}
Checking account…