Data Structures & AlgorithmsVery hardICPC regional · Product Company SDE

Problem: A wooden stick of length 7 must be cut at the marked positions 1, 3, 4 and 5 (measured from one end). Each cut costs the current length of the piece being cut, and cuts may be done in any order. What is the minimum total cost?

  1. A. 20
  2. B. 19
  3. C. 16
  4. D. 28

Correct answer: C. 16

Cut at 3 first (7), then the left piece [0,3] at 1 (3) and the right piece [3,7] at 5 then 4 (4 + 2), total 16. Left-to-right costs 20, right-to-left 19, and 7 × 4 = 28 charges the full stick for every cut.

More Coding Interview Problems questions

Exams that ask this topic