Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: In the string "abcbaxyzzyx", count the palindromic substrings of length exactly 5.
- A. 2
- B. 1
- C. 0
- D. 3
Correct answer: B. 1
Test each length-5 window against its reverse. Palindromes of other lengths, such as the length-3 'bcb', are excluded by the question.
More Coding Interview Problems questions
- Problem: How many adjacent positions i (0 ≤ i < n−1) of "abbaabab" form the pair "ab" or the pair "ba"?
- Problem: How many indices i satisfy s[i] = s[i+2] in the string "abcabcab" (0 ≤ i ≤ n−3)?
- Problem: How many distinct strings are obtained from "abab" by cyclic rotations (including the rotation by 0)?
- Problem: What is the minimum number of character replacements needed to make "abcdba" a palindrome?
- Problem: In how many ways can 100 be made using coins 1, 5, 10, 25 (order does not matter)?
- Problem: How many binary strings of length 5 contain no three consecutive 1s?