Data Structures & AlgorithmsVery hard
How many contiguous subarrays of length exactly 3 in 1 2 1 3 3 2 3 1 1 read the same forwards and backwards?
- A. 1
- B. 5
- C. 2
- D. 3
Correct answer: C. 2
A length-3 block is a palindrome exactly when its first and last values are equal; the middle element is unrestricted. Checking adjacent equality or the opposite condition tests a different property.
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 1 2 3 1 2 4 1 contain EXACTLY three distinct values?
- How many contiguous subarrays of 2 4 3 6 1 5 have a sum that is divisible by the number of DISTINCT values in them?
- For every window of exactly 3 consecutive elements of 7 3 9 4 8 2 6, compute (maximum − minimum) inside that window. What is the SMALLEST…
- A sorted linked list holds 1 2 2 3 3 3 4 4 4 4. Delete nodes so that each value keeps AT MOST TWO nodes, preserving order. How many nodes…
- How many different valid sequences of PUSH and POP operations are there for a stack that performs exactly 6 pushes and 6 pops in total…
- How many contiguous subarrays of 3 1 2 4 2 3 1 2 have a sum EXACTLY equal to twice their length?