Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: The string "racecar" has length 7. How many of its substrings are palindromes with length at least 3? Count index ranges.
- A. 3
- B. 4
- C. 2
- D. 5
Correct answer: A. 3
Each index range of length at least 3 is tested against its reverse. Counting only the maximal palindromes (not their inner palindromes) gives a smaller count.
More Coding Interview Problems questions
- Problem: Count the pairs (i, j) with i < j in the array [1, 5, 2, 8, 3, 5] whose absolute difference is at most 2.
- Problem: A dice-throwing game: starting at 0, each throw adds a value from 1 to 6, and the player stops as soon as the total is at least…
- Problem: Dijkstra is run on a directed graph with arcs 0→1 (5), 0→2 (2), 2→1 (1), 1→3 (2), 2→3 (7), 3→4 (1), 2→4 (9). Each vertex is…
- Problem: A directed graph on vertices 0–4 has arcs 0→1, 1→2, 2→0, 2→3, 3→4. How many distinct simple directed cycles does it contain?
- Problem: An undirected graph on 6 vertices has edges 0-1, 1-2, 2-3, 3-0, 3-4, 4-5. Find the number of vertices whose removal leaves a…
- Problem: The rooted tree (root 0) has children 0: [1, 2], 1: [3, 4], 2: [5], 4: [6, 7], 5: [8]. Nodes are numbered in DFS pre-order with…