FastPrepMinimum Matrix-Chain Multiplications
Problems/Minimum Matrix-Chain Multiplications

Minimum Matrix-Chain Multiplications

GSA Capital logoGSA Capital● HardFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The original report names matrix-chain dynamic programming but does not give the runnable input or the exact return value. This version takes an array of dimensions and returns the minimum number of scalar multiplications. Our version is about 90% the same as the reported question.

You are given a chain of n matrices that must be multiplied in order. Matrix i has size dimensions[i - 1] x dimensions[i], so each matrix fits with the next one. You may place the parentheses any way you like. The final product is always the same, but the number of scalar multiplications can change.

Return the smallest number of scalar multiplications needed to multiply the whole chain. You only need this count, so do not build the matrices.

Function

minimumMultiplications(dimensions: int[]) → long

Examples

Example 1

dimensions = [40,20,30,10,30]return = 26000

The best order is ((A1 x (A2 x A3)) x A4), with cost 6000 + 8000 + 12000 = 26000.

Example 2

dimensions = [10,20,30]return = 6000

Two matrices have only one possible multiplication order, costing 10 x 20 x 30 = 6000.

Example 3

dimensions = [10,30,5,60]return = 4500

Multiplying the first two matrices before the third costs 1500 + 3000 = 4500.

Constraints

  • 2 <= dimensions.length <= 101
  • Every dimension is a positive integer.
  • The cost of any single matrix multiplication, and every candidate total the standard dynamic programming checks, are less than 2^62.

Similar questions at other companies

  • Split Array to Minimize the Largest SumNation with NaMo · PHONE SCREEN
  • Trapping Rain WaterOracle · PHONE SCREEN
  • Minimum Length After Removing Arithmetic TriplesMedia.net · PHONE SCREEN
  • Select Transactions with Child-Pays-for-Parent PackagesCoinbase · PHONE SCREEN
  • Longest Consistent Activity StreakAtlassian · PHONE SCREEN
  • Longest Increasing Path in a MatrixNew Relic · PHONE SCREEN · ONSITE INTERVIEW
  • Longest Increasing Subsequence With Bounded Adjacent DifferenceGoogle · PHONE SCREEN
  • Longest Increasing Subsequence With Bounded Adjacent DifferenceAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Maximum Profit with at Most K TransactionsTekion · PHONE SCREEN
  • Count Ordered Combination Sums with Negative ValuesPinterest · PHONE SCREEN
See GSA Capital hiring insights
Saved
class Solution {
    public long minimumMultiplications(int[] dimensions) {
        // write your code here
    }
}
Checking account…