Data Structures & AlgorithmsModerateTCS NQT Digital · Accenture
Problem: The string "abba" has how many palindromic substrings (counted by index range)?
- A. 6
- B. 4
- C. 2
- D. 10
Correct answer: A. 6
Palindromic ranges: a, b, b, a, "bb", "abba" = 6. Distinct palindromes give 4, multi-letter ones give 2, and 10 counts all substrings.
More Coding Interview Problems questions
- Problem: How many occurrences of "ab" are in "ababab" when occurrences may overlap?
- Problem: In the string "dvdf", what is the length of the longest substring with all distinct characters?
- Problem: The number of ways to tile a 1×4 strip completely using tiles of length 1 and length 2 (tiles of the same length are…
- Problem: In the binary string "0011100", what is the length of the longest contiguous substring that contains equal numbers of 0s and 1s?
- Problem: How many strings of length 3 over the alphabet {a, b, c} contain no two consecutive a's?
- Problem: The number of subsets of {1, 2, 3, 4} whose elements sum to exactly 5 (the empty set is excluded) is what value?