GATE Computer ScienceVery hardGATE CS (PYQ pattern)

Balloons with numbers [3, 1, 5, 8, 2, 6] are burst one at a time. Bursting a balloon with neighbours l and r (a missing neighbour counts as 1) earns l × value × r, and then the neighbours become adjacent. What is the maximum total number of coins?

  1. A. 432
  2. B. 465
  3. C. 480
  4. D. 508

Correct answer: B. 465

Think of the last balloon burst in each interval: dp[i][j] = max over k of dp[i][k] + dp[k][j] + a[i]·a[k]·a[j] with sentinels 1 at both ends. This gives 465 for this input (checked by running the DP).

More Algorithms questions

Exams that ask this topic