Data Structures & AlgorithmsModerateGATE CS · Product-company placement

In how many different ways can 'pineapplepen' be split into a sequence of words from the dictionary {pine, apple, pen, pineapple, applepen, pin, e} (every character used, order kept)?

  1. A. 4
  2. B. 6
  3. C. 5
  4. D. 10

Correct answer: C. 5

ways[i] = Σ ways[j] over dictionary words s[j..i−1], with ways[0] = 1; ways[12] = 5.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic