Problem · Heap
Reduce the Array (Also for DA)
Learn this problemProblem statement
Given an integer array, reduce the array to a single element.
In each operation, pick two indices i and j (where i ≠ j), and:
a[i] + a[j] to the arraya[i] and a[j] from the arrayThe cost of each operation is a[i] + a[j]. Find the minimum possible cost to reduce the array.
Function
minimizeCost(arr: int[]) → int
Complete the function minimizeCost in the editor.
minimizeCost has the following parameter:
int arr[n]: an array of integers
Returns
int: the minimum cost of reducing the array
Examples
Example 1
arr = [25, 10, 20]return = 85Consider array [25,10,20].
- Pick 10 and 20, cost = 10+20 = 30, array' = [25,30]
- Pick 25 and 30, cost = 25+30 = 55, array" = [55]
Constraints
2 ≤ n ≤ 10^51 ≤ arr[i] ≤ 100
More JPMorgan Chase problems
- Bitwise XOR SubsequencesOA · Seen Jul 2026
- Array ChallengeOA · Seen Jun 2026
- Minimum Cores to Handle ProcessesOA · Seen Jun 2026
- About ShippingOA · Seen Jun 2026
- Count Dropped RequestsOA · Seen Jan 2026
- Generate Table of ContentsOA · Seen Jan 2026
- Calculate Net ProfitOA · Seen Jun 2025
- Find Total WeightOA · Seen Jun 2025