PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/MathWorks

Minimize reduction cost and validate equal-sum pairs

Last updated: Mar 29, 2026

Quick Overview

This two-part question evaluates array manipulation and algorithmic problem-solving skills: the first task focuses on optimizing cumulative operation costs during iterative reductions while the second assesses combinatorial pairing under equal-sum constraints and computation of aggregate pairwise products.

  • medium
  • MathWorks
  • Coding & Algorithms
  • Software Engineer

Minimize reduction cost and validate equal-sum pairs

Company: MathWorks

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given two independent coding tasks. ## Task 1: Minimum total cost to reduce an array You are given an integer array `arr` of length `n`. You may repeatedly perform the following **reduction** operation until only one number remains: 1. Choose any two elements `x` and `y` currently in the array. 2. Remove both from the array. 3. Insert their sum `x + y` back into the array. 4. The **cost** of this operation is `x + y`. Return the **minimum possible total cost** over all sequences of operations. **Input:** `arr` (integers) **Output:** minimum total cost (use 64-bit integer) **Notes/assumptions (make explicit in your solution):** - `n >= 1`. - Elements can be any integers; total cost should be computed using 64-bit arithmetic. --- ## Task 2: Pair elements into equal-sum groups and sum products You are given an integer array `arr` of **even** length `2m`. You must partition the array into `m` disjoint pairs such that: - Every element is used in exactly one pair. - The **sum of the two numbers in each pair is the same constant** `S` for all pairs. If such a partition is possible, return: - The value \(\sum_{i=1}^{m} (a_i \times b_i)\), i.e., the **sum of products** of each pair. If it is **not** possible to form such pairs, return `-1`. **Input:** `arr` (even length) **Output:** sum of pairwise products, or `-1` (use 64-bit integer)

Quick Answer: This two-part question evaluates array manipulation and algorithmic problem-solving skills: the first task focuses on optimizing cumulative operation costs during iterative reductions while the second assesses combinatorial pairing under equal-sum constraints and computation of aggregate pairwise products.

Related Interview Questions

  • Minimize shortest path by adding weight-1 edges - MathWorks (easy)
  • Maximize minimum after K decrements - MathWorks (easy)
  • How to maximize rewards with exactly k tasks - MathWorks (easy)
  • Maximize minimum value after k decrements - MathWorks (medium)
  • Determine Whether P's Position Is Unique - MathWorks (medium)
MathWorks logo
MathWorks
Jan 6, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
0
0
Loading...

You are given two independent coding tasks.

Task 1: Minimum total cost to reduce an array

You are given an integer array arr of length n.

You may repeatedly perform the following reduction operation until only one number remains:

  1. Choose any two elements x and y currently in the array.
  2. Remove both from the array.
  3. Insert their sum x + y back into the array.
  4. The cost of this operation is x + y .

Return the minimum possible total cost over all sequences of operations.

Input: arr (integers)

Output: minimum total cost (use 64-bit integer)

Notes/assumptions (make explicit in your solution):

  • n >= 1 .
  • Elements can be any integers; total cost should be computed using 64-bit arithmetic.

Task 2: Pair elements into equal-sum groups and sum products

You are given an integer array arr of even length 2m.

You must partition the array into m disjoint pairs such that:

  • Every element is used in exactly one pair.
  • The sum of the two numbers in each pair is the same constant S for all pairs.

If such a partition is possible, return:

  • The value ∑i=1m(ai×bi)\sum_{i=1}^{m} (a_i \times b_i)∑i=1m​(ai​×bi​) , i.e., the sum of products of each pair.

If it is not possible to form such pairs, return -1.

Input: arr (even length)

Output: sum of pairwise products, or -1 (use 64-bit integer)

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More MathWorks•More Software Engineer•MathWorks Software Engineer•MathWorks Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,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.