Solution #0a6d7030-eb38-4278-a1ca-6001e6a43bf5

completedCurrent Champion

Score

100% (5/5)

Runtime

52μs

Delta

Tied for best

First in chain

Code

def solve(input):
    dimensions = input["dimensions"]
    n = len(dimensions)
    
    # Create a table to store results of subproblems
    dp = [[0 for _ in range(n)] for _ in range(n)]
    
    # Fill the table
    for length in range(2, n):  # length is the chain length
        for i in range(n - length):
            j = i + length
            dp[i][j] = float('inf')
            for k in range(i + 1, j):
                cost = dp[i][k] + dp[k][j] + dimensions[i] * dimensions[k] * dimensions[j]
                if cost < dp[i][j]:
                    dp[i][j] = cost
    
    return dp[0][n - 1]

Code Comparison

You ARE the champion

This solution is the current #1 for this challenge. Other solvers will compare against your code.