Data Structures & AlgorithmsHardGATE CS · TCS NQT
How many contiguous subarrays of [1, 1, 2, 2, 2, 3] contain only one distinct value?
- A. 10
- B. 11
- C. 12
- D. 14
Correct answer: A. 10
Runs of equal values of length L give L(L+1)/2 subarrays: runs 2, 3 and 1 contribute 3, 6 and 1.
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 index pairs i < j in [1, 4, 7, 2, 5, 8] satisfy that a[i] - a[j] is divisible by 3?
- How many substrings of the string aaabaa consist only of the letter a?
- What is the length of the longest proper prefix of abcab that is also a suffix of abcab (the border)?
- What is the number of occurrences of the pattern abab in the string ababababab, counting overlapping matches?
- How many binary strings of length 5 contain no two consecutive zeros?
- What is the lexicographically smallest string obtainable from cbad by swapping exactly one pair of characters?