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?
- A. 20
- B. 19
- C. 16
- 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
- Problem: The elimination game: numbers 1 to 9 are written in a row. Repeatedly remove alternate numbers, starting from the left, then from…
- Problem: The 3-bit Gray code sequence is 000, 001, 011, 010, 110, 111, 101, 100 for indices 0 to 7. What is the decimal value of the…
- Problem: How many subsets (including the empty set) of [1, 2, 3, 4, 5] have bitwise XOR equal to 0?
- Problem: How many integers from 1 to 100 are divisible by exactly one of 2 and 3?
- Problem: What is the last non-zero decimal digit of 10! (3628800)?
- Problem: Five people (including Alice and Bob) stand in a row. In how many arrangements do Alice and Bob stand next to each other?