Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: The string "racecar" is compared with its reverse position by position. How many positions have matching characters?
- A. 3
- B. 6
- C. 1
- D. 7
Correct answer: D. 7
"racecar" is a palindrome, so s[i] = s[6 − i] at all 7 positions. Counting only mirrored pairs gives 3, leaving out the middle gives 6, and 1 counts only the centre.
More Coding Interview Problems questions
- Problem: Starting with the number 1, double it and add 1 repeatedly. What is the value after the 10th doubling step (starting value 1, 10…
- Problem: The array [2, 4, 3, 1, 6, 5] is partitioned into the largest possible number of consecutive chunks such that after sorting each…
- Problem: A string of length 4 over {0, 1} has an even number of 1s. How many such strings are palindromes?
- Problem: The product 2^3 · 3^2 · 5^1 · 7^2 has how many positive divisors?
- Problem: For the array [1, 3, 5, 7, 9], how many subarrays have an average equal to 5?
- Problem: The string "aabbccdd" has all its letters doubled. How many substrings of length 2 consist of two identical letters?