PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Morgan Stanley

Compute minimal cost to merge numbers

Last updated: Mar 29, 2026

Quick Overview

This question evaluates algorithm design and data structure competency, focusing on greedy strategies, cost-optimization reasoning, and robust handling of numerical edge cases.

  • Medium
  • Morgan Stanley
  • Coding & Algorithms
  • Software Engineer

Compute minimal cost to merge numbers

Company: Morgan Stanley

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Take-home Project

Given an array of positive integers, you may repeatedly perform the following operation until one number remains: choose any two numbers x and y, pay a cost of x + y, and insert x + y back into the array. Compute the minimal possible total cost. Describe the algorithm, prove why it is optimal, analyze time and space complexity, and implement it in C++. Discuss edge cases such as n = 1, duplicate values, and very large integers.

Quick Answer: This question evaluates algorithm design and data structure competency, focusing on greedy strategies, cost-optimization reasoning, and robust handling of numerical edge cases.

Related Interview Questions

  • Implement Factorial and Squares - Morgan Stanley (medium)
  • Compute maximum non-overlapping meetings - Morgan Stanley (medium)
  • How do you escape the circle? - Morgan Stanley (medium)
  • Compute win probability in coin-toss game - Morgan Stanley (easy)
  • Count decodings of a digit string - Morgan Stanley (Medium)
Morgan Stanley logo
Morgan Stanley
Jul 16, 2025, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
3
0

Given an array of positive integers, you may repeatedly perform the following operation until one number remains: choose any two numbers x and y, pay a cost of x + y, and insert x + y back into the array. Compute the minimal possible total cost. Describe the algorithm, prove why it is optimal, analyze time and space complexity, and implement it in C++. Discuss edge cases such as n = 1, duplicate values, and very large integers.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Morgan Stanley•More Software Engineer•Morgan Stanley Software Engineer•Morgan Stanley Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.