Data Structures & AlgorithmsHardTCS NQT · Infosys
Problem: The string "racecar" is compressed by storing each character and the number of distinct palindromic substrings of length at least 2 that start at that character. What is the total number of distinct palindromic substrings of length at least 2 in "racecar"?
- A. 4
- B. 2
- C. 3
- D. 5
Correct answer: C. 3
Collect the distinct palindromic substrings of length at least two (such as 'aceca', 'cec', 'racecar') in a set. Counting by starting position gives a different total.
More Coding Interview Problems questions
- Problem: What is the sum of all integers below 1000 that are multiples of 3 or 5? Run the code. python print(sum(x for x in range(1000) if…
- Problem: How many divisors does 10^6 have? Run the code. python print(sum(1 for d in range(1, 10 6 + 1) if (10 6) % d == 0)) What is…
- Problem: What is the largest prime below 1000? Run the code. python def isp(n): return n > 1 and all(n % d for d in range(2, int(n 0.5) +…
- Problem: How many paths go from (0,0) to (4,4) on a 5 x 5 grid using right and down moves while avoiding cell (2,2)? Run the DP. python n…
- Problem: How many ordered pairs (x, y) with 1 <= x < y <= 50 have x y a perfect square? Run the code. python print(sum(1 for x in range(1…
- Problem: How many ways are there to write 50 as an ordered sum a^2 + b^2 with a, b >= 0? Run the code. python print(sum(1 for a in…