Matrix Chain Multiplication Problem Statement
You are provided with a chain of matrices A1, A2, A3, ..., An. The goal is to determine the minimum number of scalar multiplications needed to multiply these matrices together. A matrix chain A1, A2, A3, ..., An is defined by an array ‘arr’, where the dimensions of the 1st matrix is arr[0] * arr[1], the 2nd matrix is arr[1] * arr[2], and so forth.
Input:
The first line contains an integer ‘T’, representing the number of test cases. For each test case: The first line contains an integer ‘N’, the number of elements in the array. The second line contains ‘N’ space-separated integers representing the elements of the array.
Output:
For each test case, output a single integer representing the minimum cost of matrix multiplication. Each result should be printed on a separate line.
Example:
Input: arr = [10, 20, 30, 40] Output: The cost for the optimal multiplication order, given A1 dimensions of [10 * 20], A2 of [20 * 30], and A3 of [30 * 40], would be calculated.
Constraints:
1 <= T <= 5
2 <= N <= 100
1 <= arr[i] <= 400
- Time Limit:
1 sec
Note:
No need for output handling; focus on implementing the core functionality in the function as specified.
Be the first one to answer
Add answer anonymously...
Top ACKO Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app