Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Connect Sticks

Minimum Cost to Connect Sticks gives an array of positive lengths. Repeatedly combine any two sticks, paying their combined length each time, and return the smallest total cost to leave one stick.

Statement

You are given a set of sticks with positive integer lengths represented as an array, sticks, where sticks[i] denotes the length of the ithi^{th} stick.

You can connect any two sticks into one stick at a cost equal to the sum of their lengths. Once two sticks are combined, they form a new stick whose length is the sum of the two original sticks. This process continues until there is only one stick remaining.

Your task is to determine the minimum cost required to connect all the sticks into a single stick.

Constraints:

  • 1≤1 \leq sticks.length ≤103\leq 10^3

  • 1≤1 \leq sticks[i] ≤103\leq 10^3

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Connect Sticks

Minimum Cost to Connect Sticks gives an array of positive lengths. Repeatedly combine any two sticks, paying their combined length each time, and return the smallest total cost to leave one stick.

Statement

You are given a set of sticks with positive integer lengths represented as an array, sticks, where sticks[i] denotes the length of the ithi^{th} stick.

You can connect any two sticks into one stick at a cost equal to the sum of their lengths. Once two sticks are combined, they form a new stick whose length is the sum of the two original sticks. This process continues until there is only one stick remaining.

Your task is to determine the minimum cost required to connect all the sticks into a single stick.

Constraints:

  • 1≤1 \leq sticks.length ≤103\leq 10^3

  • 1≤1 \leq sticks[i] ≤103\leq 10^3