Company: Harness On campus Sdet_19march
Difficulty: medium
A continuous-delivery platform runs a deployment pipeline made up of a sequence of ordered stages. To speed things up, an engineer is allowed to merge two adjacent stages into one combined stage. Merging two adjacent stages produces a new stage whose workload equals the sum of the two originals, and doing that merge costs an amount equal to that combined workload. The engineer keeps merging pairs of adjacent stages until only one stage remains. Given the sequence of stage workloads, work out the lowest total cost of merging every stage down to a single one by repeatedly combining adjacent stages. Example workloads = [7, 6, 8, 6, 1, 1] One cost-minimizing sequence of merges: (7, 6, 8, 6, 1, 1) merge 1+1=2, cost=2 -> (7, 6, 8, 6, 2) (7, 6, 8, 6, 2) merge 6+2=8, cost=8 -> (7, 6, 8, 8) (7, 6, 8, 8) merge 7+6=13, cost=13 -> (13, 8, 8) (13, 8, 8) merge 8+8=16, cost=16 -> (13, 16) (13, 16) merge 13+16=29, cost=29 -> (29) Total cost = 2 + 8 + 13 + 16 + 29 = 68 Return 68 Function