Data Structures & AlgorithmsHard
How many contiguous windows of length exactly 5 in 1 2 3 4 5 6 7 8 9 10 2 have a PRIME sum?
- A. 3
- B. 7
- C. 1
- D. 0
Correct answer: D. 0
A fixed window of length 5 has its sum updated by adding the entering value and removing the leaving one. Odd sums are only a necessary condition for primes, and changing the window length answers a different question.
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
- How many contiguous subarrays of 2 4 6 4 2 8 have an AVERAGE exactly equal to the average of the whole array?
- For 3 9 1 7 2 8 4, split the array into a non-empty left part and a non-empty right part at some position p. What is the LARGEST possible…
- Using only swaps of ADJACENT characters, what is the minimum number of swaps needed to move ALL letters 'x' of "bxaxxbx" to the very front…
- From the digit string "53412", delete EXACTLY two characters (the remaining characters keep their order). What is the lexicographically…
- How many DISTINCT non-empty strings can be formed as subsequences (characters taken in order, not necessarily adjacent) of "abab"?
- Arrange the numbers 3 30 34 5 9 in some order and concatenate their decimal digits. What is the LARGEST number that can be produced?