Data Structures & AlgorithmsVery hard

What is the length of the longest contiguous subarray of 3 6 9 4 12 18 5 in which EVERY element is divisible by the FIRST element of that subarray?

  1. A. 4
  2. B. 3
  3. C. 1
  4. D. 2

Correct answer: B. 3

Fix the start of the subarray and extend right while each element stays divisible by that starting value. Checking the last element instead, or using the fixed divisor 3, tests a different condition.

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

Exams that ask this topic