Data Structures & AlgorithmsVery hardGATE CS · CAT · MBA placement

How many arrays of length 4 with entries from {1, 2, ..., 3} are NON-INCREASING (each entry is at least the next)?

  1. A. 20
  2. B. 10
  3. C. 15
  4. D. 81

Correct answer: C. 15

A non-increasing array is determined by how many times each value is used, i.e. by a multiset of size n from m values: C(n + m − 1, n). Ordered tuples with a condition on adjacent pairs are exactly what this counts.

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

Exams that ask this topic