Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 C

A frog starts at position 0 and wants to reach position 12 on a number line. Each move it jumps forward by 1, 3 or 4 units. In how many different ordered sequences of jumps can it reach exactly 12?

  1. A. 927
  2. B. 60
  3. C. 169
  4. D. 84

Correct answer: C. 169

Let ways[x] be the number of jump sequences that land on x, so ways[x] = ways[x−1] + ways[x−3] + ways[x−4]. The sequences differ by order, so this counts every path rather than the number of distinct sets of jumps.

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

Exams that ask this topic