Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many arrays of length 3 with entries from {1, 2, ..., 3} have a maximum entry of exactly 2?

  1. A. 15
  2. B. 3
  3. C. 27
  4. D. 7

Correct answer: D. 7

Count arrays with all entries ≤ k minus arrays with all entries ≤ k − 1: that is k^n − (k−1)^n. Counting arrays that contain k at least once with a single placement of k overcounts.

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

Exams that ask this topic