Ctrl K

Cheapest Three-Piece Cut

Easy
You are given an array values. Cut it into three non-empty consecutive pieces: every element lands in exactly one piece and the order is kept. The price of a piece is its **first** element. The price of the cut is the sum of the prices of the three pieces. Return the lowest possible price of a cut.
Example 1
values=[7, 9, 2, 6, 3] → 12

Cut it as [7, 9], [2, 6], [3] for a price of 7 + 2 + 3 = 12. The first piece always starts with 7, so the other two should start at the smallest numbers.

Example 2
values=[4, 4, 4] → 12

There is only one way, one number per piece: 4 + 4 + 4 = 12.

Example 3
values=[1, 20, 5, 8, 30] → 14
Constraints
  • 3 ≤ len(values) ≤ 50
  • 1 ≤ values[i] ≤ 50
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsEven Numbers From Digit Cards EasyOriginal Array From Two Shifts HardLevel the Jars MediumFlowerbed Beauty on a Budget HardBest Four-Town Route Hard
loading Python…
Input
values=[7, 9, 2, 6, 3]
Expected
12

Run checks the first 3 tests in your browser. Submit checks all 111 tests on the server, hidden ones included.