Data Structures & AlgorithmsModerate
How many contiguous windows of length 3 in 1 2 3 1 2 2 4 5 consist of three DIFFERENT values?
- A. 2
- B. 6
- C. 4
- D. 5
Correct answer: C. 4
A window of length 3 has three different values exactly when no two of its three entries coincide, so check all three pairs or the set size. Looking only at the outer entries or at adjacent pairs gives a different count.
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 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…
- How many contiguous subarrays of 1 5 2 7 3 4 8 contain EXACTLY one element whose value is at least 5?
- What is the minimum number of characters to delete from "aabbbcaa" so that no two ADJACENT characters are equal?
- How many contiguous windows of length 3 in 5 3 4 6 2 7 1 8 are STRICTLY monotone (strictly increasing or strictly decreasing)?
- How many adjacent pairs (A[i], A[i+1]) in 4 7 2 9 1 8 5 6 have a sum of at least 10?
- In the 'maximum number of disjoint pairs with sum K' problem, why is a count-based greedy optimal?