Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: How many occurrences of "ab" are in "ababab" when occurrences may overlap?
- A. 4
- B. 3
- C. 2
- D. 5
Correct answer: B. 3
The pair 'ab' starts at indices 0, 2 and 4, so there are three occurrences.
More Coding Interview Problems questions
- Problem: In the string "dvdf", what is the length of the longest substring with all distinct characters?
- Problem: The number of ways to tile a 1×4 strip completely using tiles of length 1 and length 2 (tiles of the same length are…
- Problem: In the binary string "0011100", what is the length of the longest contiguous substring that contains equal numbers of 0s and 1s?
- Problem: How many strings of length 3 over the alphabet {a, b, c} contain no two consecutive a's?
- Problem: The number of subsets of {1, 2, 3, 4} whose elements sum to exactly 5 (the empty set is excluded) is what value?
- Problem: The number of ways to make 15 using coins of values 2, 3 and 5, where the order of coins does not matter, is what value?