FastPrepFind Total Cost
Problems/Find Total Cost

Find Total Cost

JP Morgan Chase logoJP Morgan Chase● MediumNEW GRADINTERNOA

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This practice problem matches about 99% of the reported question. It preserves the forced minimum-and-maximum merge, its cost formula, and the source constraints.

Given an array arr of n integers, a sequence of n-1 operations must be performed on the array.

In each operation,

  • Remove the minimum and maximum elements from the current array and add their sum back to the array.
  • The cost of an operation, cost = ceil((minimum_element + maximum_element) / (maximum_element-minimum_element + 1)).

Find the total cost to reduce the array to a single element.

Function

findTotalCost(arr: int[]) → int

Examples

Example 1

arr = [2, 3, 4, 5, 7]return = 8
  1. Choose 2 and 7: cost ceil(9 / 6) = 2. The array becomes [3,4,5,9]; total cost is 2.
  2. Choose 3 and 9: cost ceil(12 / 7) = 2. The array becomes [4,5,12]; total cost is 4.
  3. Choose 4 and 12: cost ceil(16 / 9) = 2. The array becomes [5,16]; total cost is 6.
  4. Choose 5 and 16: cost ceil(21 / 12) = 2. The array becomes [21]; total cost is 8.

Constraints

  • 2 <= arr.length <= 2 * 10^5.
  • 1 <= arr[i] <= 10^6.

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
  • 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
  • Maximum Game Board ScoreOA · Seen Sep 2026

Similar questions at other companies

  • Split Tender Part 2 - Expiration DatesStripe · OAStripe interview questions
  • Organization Reputation After Employee DeparturesHSBC · OAHSBC interview questions
  • Last Object Exit TimeIBM · OAIBM interview questions
  • Capping Portfolio WeightsCapstone Investment Advisors · OA
  • Bold Play to Reach a GoalSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Repeated Mirror XORMathWorks · OAMathWorks interview questions
  • Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
  • Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
  • Macaron Order PriceOpenAI · OAOpenAI interview questions
  • Daily Settlement for Long and Short PositionsBelvedere Trading · OA

JP Morgan Chase interview experiences

  • JPMorgan Chase Experienced SWE Java Interview: 1 Experience
  • 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
  • JPMorgan Code for Good India 2024: 6 Experiences (Part 5 of 5)
All JP Morgan Chase interview questionsSee JP Morgan Chase hiring insights
Saved
class Solution {
    public int findTotalCost(int[] arr) {
      // write your code here
    }

}
Checking account…