Minimum Score Triangulation of Polygon - Problem
Polygon Triangulation Optimization Challenge

Imagine you have a convex polygon with n vertices, where each vertex has a specific integer value. Your task is to triangulate this polygon (divide it into triangles) in the most optimal way possible.

๐ŸŽฏ The Goal: Find the triangulation that minimizes the total score, where each triangle's score equals the product of its three vertex values.

๐Ÿ“ Rules:
โ€ข You can only create triangles using the polygon's original vertices
โ€ข Every triangulation of an n-sided polygon creates exactly n-2 triangles
โ€ข The vertices are given in clockwise order in the input array

Example: For a quadrilateral with values [3,7,4,5], you can triangulate it in two ways:
โ€ข Diagonal 3-4: triangles (3,7,4) and (3,4,5) โ†’ score = 84 + 60 = 144
โ€ข Diagonal 7-5: triangles (3,7,5) and (7,4,5) โ†’ score = 105 + 140 = 245

Return the minimum possible total score.

Input & Output

example_1.py โ€” Basic Quadrilateral
$ Input: [1,2,3]
โ€บ Output: 6
๐Ÿ’ก Note: With only 3 vertices, we have exactly one triangle (1,2,3) with score 1ร—2ร—3 = 6
example_2.py โ€” Simple Quadrilateral
$ Input: [3,7,4,5]
โ€บ Output: 144
๐Ÿ’ก Note: Two possible triangulations: diagonal 3-4 gives triangles (3,7,4) + (3,4,5) = 84+60=144. Diagonal 7-5 gives (3,7,5) + (7,4,5) = 105+140=245. Minimum is 144.
example_3.py โ€” Pentagon
$ Input: [1,3,1,4,1,5]
โ€บ Output: 13
๐Ÿ’ก Note: For this hexagon, the optimal triangulation creates 4 triangles with minimum total score of 13

Constraints

  • n == values.length
  • 3 โ‰ค n โ‰ค 50
  • 1 โ‰ค values[i] โ‰ค 100
  • The polygon is convex

Visualization

Tap to expand
Minimum Score Triangulation374512Triangulation creates4 triangles (n-2 = 6-2)Each triangle cost =product of vertex valuesGoal: Find triangulation with minimum total cost
Understanding the Visualization
1
Identify Polygon
Start with convex polygon with labeled vertex values
2
Choose Diagonal
Pick a diagonal to create first triangle
3
Recursive Division
Recursively triangulate remaining parts
4
Calculate Cost
Sum up products of triangle vertices
Key Takeaway
๐ŸŽฏ Key Insight: This is an interval DP problem where we build optimal solutions from smaller polygon segments
Asked in
Google 25 Amazon 18 Meta 12 Microsoft 8
62.0K Views
Medium Frequency
~25 min Avg. Time
1.5K Likes
Ln 1, Col 1
Smart Actions
๐Ÿ’ก Explanation
AI Ready
๐Ÿ’ก Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen