Minimum Score Triangulation of Polygon

MediumDynamic Programminginterval dp

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

A convex polygon has n vertices labeled with positive integers values[0..n-1] in clockwise order. Triangulate the polygon into n - 2 triangles using non-crossing diagonals. Each triangle scores the **product** of its three vertex labels, and a triangulation's total score is the sum over all its triangles. Return the smallest total score over all possible triangulations.

Examples

Input: values = [1,2,3]
Output: 6
The polygon is already a single triangle: 1 * 2 * 3.
Input: values = [3,7,4,5]
Output: 144
Splitting along 3-4 gives 3*7*4 + 3*4*5 = 144; splitting along 7-5 gives 3*7*5 + 7*4*5 = 245.
Input: values = [1,3,1,4,1,5]
Output: 13
The best triangulation scores 1*1*3 + 1*1*4 + 1*1*5 + 1*1*1 = 13.

Constraints

  • `3 <= n <= 50`
  • `1 <= values[i] <= 100`

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More interval dp problems