Data Structures & AlgorithmsVery hardICPC regional · Product Company SDE
Problem: In the string "racecarbanana", find the number of distinct palindromic substrings of length at least 3.
- A. 7
- B. 6
- C. 12
- D. 2
Correct answer: B. 6
The distinct palindromes of length ≥ 3 are racecar, aceca, cec, ana, anana and nan: 6. Counting occurrences counts 'ana' twice (7), dropping the length filter adds the single letters r, a, c, e, b, n (12), and keeping only maximal palindromes gives 2.
More Coding Interview Problems questions
- Problem: On a line of 12 cells (1–12), a robot starts at cell 1. Each second it moves to the cell i+3 if that cell is still ≤ 12 and not…
- Problem: A string is built by writing the first 15 positive integers in binary, concatenated in order (1, 10, 11, 100, ..., 1111). How…
- Problem: A sorted array [1, 3, 3, 5, 8, 8, 8, 13, 21] is searched for the value 8 using the standard lower-bound binary search (find the…
- Problem: A tree has 7 nodes 1–7 with edges 1-2, 1-3, 2-4, 2-5, 3-6, 6-7. Each node is coloured red if its depth from node 1 is even and…
- Problem: Starting with the sorted list 1, 4, 9, 16, 25, 36, two operations alternate: first remove the largest element, then append the…
- Problem: A simple graph has 6 vertices labelled 1–6. Vertex i is adjacent to j exactly when gcd(i, j) = 1 and i ≠ j. How many edges does…