Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: Count the occurrences of the pattern "aaa" in the text "aaabaaaab", where occurrences may overlap (each starting index that matches counts once).
- A. 4
- B. 2
- C. 3
- D. 5
Correct answer: C. 3
Overlapping matches start at indices 0, 4 and 5, so there are 3. Non-overlapping scanning (jumping past each match) finds only 2.
More Coding Interview Problems questions
- Problem: Round-robin scheduling with time quantum 3 is applied to processes that all arrive at time 0: P1 needs 7 units, P2 needs 4, P3…
- Problem: Josephus game: n = 37 people stand in a circle numbered 1 to 37. Starting from person 1, every 4th person is removed (counting…
- Problem: A deque starts empty. Operations in order: pushback(5), pushfront(2), pushback(8), popfront(), pushfront(9), pushback(1)…
- Problem: How many integers x in the range 1 ≤ x ≤ 1000 have exactly 4 set bits in their binary representation?
- Problem: A staircase can be climbed by steps of size 1, 3 or 4. How many distinct ordered sequences of steps climb exactly 13 stairs?
- Problem: What is the length of the longest strictly increasing subsequence of the sequence 10, 9, 2, 5, 3, 7, 101, 18, 4, 6, 8, 1, 12?