Data Structures & AlgorithmsVery hardGATE CS · TCS NQT
In the text "aaabaaaabaaa", count the occurrences of "aaa" whose starting index is a prime number (0-indexed).
- A. 2
- B. 1
- C. 0
- D. 4
Correct answer: B. 1
Find all occurrences of the pattern first (overlapping ones included), then keep only the prime start indices. The total occurrence count without the prime filter is a different answer.
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 sum over all adjacent pairs of [4, 2, 5, 1, 3] of the smaller of the two values?
- A shop has a 'buy 2, get the cheapest of the three free' deal. Items priced [3, 1, 4, 2, 5, 6] are bought in groups of three, with the…
- A circular list holds 1..10. Starting at 1, you count 4 nodes (including the current one) and delete the fourth, then continue counting…
- Buildings of heights [3, 7, 8, 3, 6, 1] are viewed from the left. How many buildings are visible (a building is visible if it is strictly…
- Evaluate the postfix expression "3 4 min 5 max 2 +" where min and max take two operands and return the smaller or larger.
- What is the length of the longest contiguous subarray of [2, 0, 0, 2, 0, 2, 2] whose sum is 0?