Data Structures & AlgorithmsModerateProduct placement · Amazon/Microsoft

For an array of n elements, how many contiguous subarrays are there, and how many subsequences (including the empty one)?

  1. A. n(n + 1)/2 and 2ⁿ
  2. B. n² and 2ⁿ − 1
  3. C. 2ⁿ and n(n + 1)/2
  4. D. n(n − 1)/2 and n!

Correct answer: A. n(n + 1)/2 and 2ⁿ

A subarray is fixed by its start ≤ end: n(n + 1)/2 choices. A subsequence keeps or drops each element independently: 2ⁿ including the empty one.

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

Exams that ask this topic