Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: The string "aabbccdd" has all its letters doubled. How many substrings of length 2 consist of two identical letters?
- A. 5
- B. 4
- C. 3
- D. 6
Correct answer: B. 4
Adjacent equal pairs occur at positions 0, 2, 4 and 6 (the doubled letters), so the answer is four.
More Coding Interview Problems questions
- Problem: A 2×4 grid has a wall at (0,2) (row, column, 0-indexed); all other cells are open. Moves go up, down, left or right. What is the…
- Problem: The complete directed graph on 4 vertices has an arc in both directions between every pair of distinct vertices. How many…
- Problem: The path graph P4 has vertices 1–4 and edges 1-2, 2-3, 3-4. How many edges does its complement graph (on the same vertices…
- Problem: A complete binary tree has 15 nodes (height 3, all levels full). How many of its nodes are leaves?
- Problem: The string "abba" has how many palindromic substrings (counted by index range)?
- Problem: How many occurrences of "ab" are in "ababab" when occurrences may overlap?