Data Structures & AlgorithmsHardTCS NQT · Codeforces Div2 B

A triangle of numbers has rows [9], [7, 6], [9, 7, 4], [6, 1, 5, 3], [6, 9, 2, 4, 5]. Starting at the top, each step goes to one of the two numbers directly below. What is the minimum possible path sum?

  1. A. 25
  2. B. 26
  3. C. 27
  4. D. 37

Correct answer: A. 25

Bottom-up DP: replace each entry with entry + min(two entries below it), then read the top. Choosing the smaller child at each row (a greedy walk) can lead into a large number further down.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic