Data Structures & AlgorithmsModerateGATE CS · CAT · MBA placement

How many sequences of length 4 with entries from {1, 2, 3} are non-decreasing (each entry is at least the one before it)?

  1. A. 21
  2. B. 65
  3. C. 4
  4. D. 15

Correct answer: D. 15

A non-decreasing sequence is fixed by how many times each value is used, which is a multiset of size 4 from 3 values: C(4 + 3 − 1, 4) = 15. Ordered sequences with the adjacency constraint are what this equals.

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

Exams that ask this topic