Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: The string "xyzzyxzz" is considered. How many of its substrings of length 3 are palindromes (counted by index)?
- A. 1
- B. 2
- C. 3
- D. 0
Correct answer: D. 0
Test each length-3 window against its reverse. Palindromes of length 2 (such as 'zz') are excluded by the length requirement.
More Coding Interview Problems questions
- Problem: Among the strings "abc", "bca", "cab", "acb", "bac", "cba", how many distinct pairs (x, y) with x ≠ y are rotations of each other…
- Problem: Find the length of the longest substring of "aaabbbbcccd" that contains at most two distinct letters.
- Problem: How many numbers from 1 to 1000 have a digit sum divisible by 9?
- Problem: How many ways are there to write 20 as an ordered sum of parts from {2, 3, 5}?
- Problem: The sequence a0 = 0 and a(n) = a(n−1) + (n mod 3) for n ≥ 1 is defined. What is a(30)?
- Problem: A square matrix 4×4 has entry (i, j) equal to (i + 2j) mod 5. What is the sum of the entries on the main diagonal?