FastPrepReduce the Array (Also for DA)
Problems/Reduce the Array (Also for DA)

Reduce the Array (Also for DA)

JP Morgan Chase logoJP Morgan Chase● MediumINTERNOA

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The source image establishes repeated pair-sum merges, charging each merged sum, until one value remains. A separate internship report names array reduction and a nested-loop approach but supplies no operation or objective. Its association with this minimum merge-cost task is an authored practice interpretation, not a verified exact historical match.

Given an integer array, reduce the array to a single element.

In each operation, pick two indices i and j (where i ≠ j), and:

  • append the value of a[i] + a[j] to the array
  • delete a[i] and a[j] from the array

The 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 = 85

Consider 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]

The cost is 30+55 = 85. This is the minimum possible cost.

Constraints

  • 2 ≤ n ≤ 10^5
  • 1 ≤ arr[i] ≤ 100

More JP Morgan Chase interview questions

  • Longest Consecutive SequencePHONE SCREEN · Seen Nov 2026
  • LFU CacheONSITE INTERVIEW · Seen Nov 2026
  • LRU CacheONSITE INTERVIEW · Seen Nov 2026
  • Find Total CostOA · Seen Oct 2026
  • Minimum Meeting RoomsOA · Seen Oct 2026
  • Count Dropped RequestsOA · Seen Oct 2026
  • Maximize Binary XOR with a Set-Bit LimitPHONE SCREEN · Seen Oct 2026
  • Maximize Minimum Deployment DifficultyOA · Seen Oct 2026
  • Task SchedulingOA · Seen Oct 2026
  • Substring RemovalOA · Seen Oct 2026

Similar questions at other companies

  • Maximum Sum of a K-StarMicrosoft · OAMicrosoft interview questions
  • Maximum ScoreNVIDIA · OANVIDIA interview questions
  • Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
  • Maximum K-Star SumC3.ai · OAC3.ai interview questions
  • Decreasing SubsequencesGoogle · OAGoogle interview questions
  • Get Maximum AmountIBM · OAIBM interview questions
  • Task SchedulerAmazon · OA · PHONE SCREEN
  • Optimize TikTok Reels ViewingTikTok · OATikTok interview questions
  • Rearrange Songs by AuthorZomato / Eternal · OAZomato / Eternal interview questions
  • Minimize the Sum with Ceiling HalvesSquarepoint Capital · OASquarepoint Capital interview questions

Interview reports that mention this question

  • JPMorgan Code for Good India 2024: 6 Experiences (Part 5 of 5)
  • JPMorgan Tech Intern HackerRank OA: 11 Experiences (Part 3 of 5)

JP Morgan Chase interview experiences

  • JPMorgan Quant Stats Superdays: 3 Experiences (Part 3 of 3)
  • JPMorgan Quant Modeling Superdays: 7 Experiences (Part 2 of 3)
  • JPMorgan Quant Intern Superday: 19 Experiences (Part 1 of 3)
  • JP Morgan Chase Data and AI Intern Superday: 11 Experiences
All JP Morgan Chase interview questionsSee JP Morgan Chase hiring insights
Saved
class Solution {
    public int minimizeCost(int[] arr) {
      // write your code here
    }

}
Checking account…