Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 B
How many subarrays of [1, 2, 1, 2, 2, 1] read the same forwards and backwards (as sequences of values)?
- A. 21
- B. 8
- C. 10
- D. 6
Correct answer: C. 10
Six single elements, plus [2,2], [1,2,1], [2,1,2] and [1,2,2,1]: 10. Expanding only around odd centres misses the even ones (8), 6 counts single elements only and 21 counts all subarrays.
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 palindromic substring of xabacdcabay?
- What is the minimum number of cuts needed to partition the string abacdcdad into palindromic pieces?
- How many times does the pattern aba occur in ababababa when occurrences may overlap?
- For the string aabaaabaa, what is the sum of the Z-function values Z[1] + Z[2] + ... + Z[n-1] (Z[i] is the longest common prefix of the…
- How many distinct substrings of length 3 does the string abcabcabd have?
- How many substrings of abcabcbb contain no repeated character?