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?
- A. 4
- B. 3
- C. 1
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the maximum sum of a contiguous subarray of 3 1 3 2 4 1 5 whose elements are all DISTINCT?
- What is the MINIMUM sum of a contiguous subarray of 4 -2 1 -5 3 2 -1 whose length is at least 3?
- In the string "cbaebabacd", how many substrings of length 3 are ANAGRAMS of "abc" (same letters, any order)?
- What is the minimum number of CONSECUTIVE elements you must delete from 1 2 6 3 4 1 5 so that the remaining elements are in non-decreasing…
- How many contiguous windows of length 3 in 1 2 3 1 2 2 4 5 consist of three DIFFERENT values?
- What is the length of the longest contiguous subarray of 4 5 6 5 4 7 8 9 10 3 in which every ADJACENT pair differs by exactly 1 (in either…