Data Structures & AlgorithmsModerateTCS NQT Digital · Accenture
Problem: The string "abracadabra" contains the substring "abra" at several positions. How many occurrences of "abra" are there (overlaps allowed)?
- A. 3
- B. 1
- C. 4
- D. 2
Correct answer: D. 2
'abra' starts at indices 0 and 7, giving two occurrences; the third 'abra' would need a fourth letter that does not exist after index 7.
More Coding Interview Problems questions
- Problem: The string "abcdefghij" is split into blocks of length 4 from the left (the last block may be shorter). How many blocks have…
- Problem: The number of permutations of the digits 1, 2, 3, 4 in which the digit 1 is not in the first position and 4 is not in the last…
- Problem: Cars pass a toll booth at times 2, 5, 6, 10, 11, 15 (minutes). A car may pass only if at least 3 minutes have elapsed since the…
- Problem: A sorted list of distinct integers is 3, 8, 12, 17, 21, 26, 30. How many pairs (i < j) have a[j] − a[i] exactly equal to 9?
- Problem: The value of 3^(3^3) mod 7 is what?
- Problem: A path graph has vertices 1–6 with edges between consecutive vertices. How many pairs of vertices are at distance exactly 2?