Statement

You are given a chain of matrices to be multiplied. You have to find the least number of primitive multiplications needed to evaluate the result.

Note: Given two matrices AA and BB of dimensions (n×m)(n \times m) and (m×l)(m \times l), the resulting matrix we get is ABAB, whose dimensions are (n×l)(n \times l). Further, when multiplying these two matrices, the number of primitive multiplications is (n×m×l)(n \times m \times l).

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.