Data Structures & AlgorithmsHardICPC regional · Product Company SDE
Problem: The string "xyyxzzyx" is examined for palindromic substrings of length 4 or more. How many such palindromic substrings are there (distinct index ranges)?
- A. 1
- B. 2
- C. 0
- D. 3
Correct answer: A. 1
Check every index range of length at least four against its reverse. The palindromes 'xyyx', 'yzzy' and the full string 'xyyxzzyx' are among those counted.
More Coding Interview Problems questions
- Problem: A binary string is "good" if it has no two consecutive zeros. How many good strings of length 7 begin with 1 and end with 1?
- Problem: A process list is [3, 7, 2, 9] with priorities; the CPU always runs the largest value next and runs it for its full value, then…
- Problem: How many subarrays of [2, 4, 6, 1, 3, 5] have all elements even or all elements odd?
- Problem: The number 9 is written in base 3 as 100. How many numbers from 1 to 100 have a base-3 representation with no digit 2?
- Problem: On a line of cells 0–9, a token starts at cell 0. Each second it moves right by 2 if the cell is even, and left by 1 if the cell…
- Problem: Count the pairs (i, j) with 1 ≤ i < j ≤ 12 for which the number i·j is a perfect square.