Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: The string "tenet" is considered. How many of its substrings (by index range, length at least 2) are palindromes?
- A. 3
- B. 2
- C. 1
- D. 4
Correct answer: B. 2
Count palindromes of length at least two by index range. The whole string 'tenet' and the inner 'ene' are palindromes, and 'te', 'en', 'ne', 'et' are not.
More Coding Interview Problems questions
- Problem: Water fills a 1-dimensional container with walls of heights [4, 1, 3, 1, 2]. Each cell holds water up to the minimum of the…
- Problem: Compute the sum of all integers from 1 to 999 whose digits are all odd.
- Problem: What is the number of ways to climb 8 steps when each move is 1, 2 or 4 steps, counted as ordered sequences?
- Problem: The array [1, 2, 3, 4, 5, 6, 7, 8, 9] is split into 3 consecutive groups of equal length. What is the sum of the middle group?
- Problem: The product of the numbers from 1 to 10, divided by the product of the numbers from 1 to 7, is what value?
- Problem: A string is "xoxoxox". How many substrings of length 3 are equal to "xox"?