Data Structures & AlgorithmsHardTCS NQT · Product Company SDE
Problem: The string "abcdcba" is checked for palindromic substrings with an odd length of at least 5. How many such substrings are there?
- A. 2
- B. 3
- C. 1
- D. 4
Correct answer: A. 2
Odd-length palindromes of length at least five are checked by brute force over index ranges of even span. Counting all palindromes of length at least three would include the length-3 ones.
More Coding Interview Problems questions
- Problem: What is the number of distinct strings of length 4 over the alphabet {a, b} containing at least one 'a' and at least one 'b'?
- Problem: The string "aabbccddee" is compressed by keeping each character once for every run of length at least two, followed by the count…
- Problem: Calculate the number of ordered pairs (x, y) of integers with 1 ≤ x, y ≤ 20 for which x² + y² is divisible by 5.
- Problem: A lattice path goes from (0,0) to (3,3) using steps right (1,0) and up (0,1), and it must never go above the diagonal (that is…
- Problem: The array [1, 2, 4, 8, 16, 32] stores powers of two. For how many pairs (i < j) is a[i] + a[j] a power of two?
- Problem: A queue of 5 customers arrives with service times 4, 2, 6, 1, 3. A single server processes them in order (first come first…