FastPrepMinimum Stick Connection Cost
Problems/Minimum Stick Connection Cost

Minimum Stick Connection Cost

Navan logoNavan● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Navan onsite interview for a full-time role. Our version follows the reported exercise. The report leaves out some input limits and interface details, and we filled those in.

Our version is about 95% the same as the reported question.

You are given an integer array sticks, where each element is the length of a stick.

You may connect any two sticks with lengths x and y. The new stick has length x + y, and the cost of this operation is also x + y.

Return the minimum total cost required to connect all sticks into one stick.

Interview follow-up

The interviewer also asked what to do when the input cannot fit in memory. Discuss how to do the same cheapest merging when the data sits on disk. Your function here gets the whole array in memory.

Function

minimumStickConnectionCost(sticks: int[]) → int

Examples

Example 1

sticks = [2, 4, 3]return = 14

Connect 2 and 3 for cost 5, then connect 5 and 4 for cost 9. The total cost is 14.

Example 2

sticks = [1, 8, 3, 5]return = 30

One optimal sequence is 1 + 3 = 4, then 4 + 5 = 9, then 8 + 9 = 17, for total cost 4 + 9 + 17 = 30.

Constraints

  • 1 <= sticks.length <= 10^4
  • 1 <= sticks[i] <= 10^4

More Navan interview questions

  • Time Based Key-Value StoreONSITE INTERVIEW · Seen Dec 2025
  • Type-Ahead Prefix MatchesONSITE INTERVIEW · Seen Dec 2024
  • Minimum Steps on a Circular Character DialONSITE INTERVIEW · Seen Jan 2024
  • Shortest Substring with at Least K Distinct CharactersONSITE INTERVIEW · Seen Jan 2024
  • Compare N-Ary Tree Leaf SequencesONSITE INTERVIEW · Seen Nov 2023
  • Roman to IntegerPHONE SCREEN · Seen Oct 2024
  • Sort ColorsPHONE SCREEN · Seen Oct 2024
  • Basic CalculatorPHONE SCREEN · Seen Jun 2024
  • LRU CachePHONE SCREEN · Seen Jun 2024
  • House RobberPHONE SCREEN · Seen May 2024

Similar questions at other companies

  • Task SchedulerAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
  • 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
  • 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
All Navan interview questionsSee Navan hiring insights
Saved
class Solution {
    public int minimumStickConnectionCost(int[] sticks) {
      // write your code here
    }
}
Checking account…