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

Connect N Ropes With Minimum Cost

InMobi logoInMobi● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an InMobi new grad online assessment. The interview report names DoSelect as the place the test was hosted. It points straight at the well-known exercise of connecting ropes at the minimum cost. Our version is about 99% 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.

More InMobi Online Assessment questions

  • Validate a Bracket SequenceOA · Seen Oct 2026
  • Count Substrings Matching with One Adjacent SwapOA · Seen Oct 2026
  • Maximum Subarray with Start and End WindowsOA · Seen Oct 2026
  • Minimum Service Cold StartsOA · Seen Oct 2026
  • Range Maximum Subarray Sum QueriesOA · Seen Oct 2026
  • Connected Components with Divisor ThresholdOA · Seen Aug 2026
  • Maximize Impression ValueOA · Seen Aug 2026
  • Supply Path OptimizationOA · Seen Aug 2026
  • Delivery ServiceOA · Seen Jun 2026
  • Shared InterestOA · Seen Jun 2026

Similar questions at other companies

  • Task SchedulerAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Minimum Cost to Merge Values into OnePayPal · OAPayPal interview questions
  • Maximum K-Star SumC3.ai · OAC3.ai interview questions
  • Maximum Sum of a K-StarMicrosoft · OAMicrosoft interview questions
  • Maximum ScoreNVIDIA · OANVIDIA interview questions
  • Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
  • Task SchedulingJP Morgan Chase · OAJP Morgan Chase interview questions
  • Decreasing SubsequencesGoogle · OAGoogle interview questions
  • Get Maximum AmountIBM · OAIBM interview questions
  • Optimize TikTok Reels ViewingTikTok · OATikTok interview questions
All InMobi interview questionsSee InMobi hiring insights
Saved
class Solution {
    public long minimumRopeConnectionCost(int[] ropes) {
      // write your code here.
    }
}
Checking account…