Data Structures & AlgorithmsHardProduct Company SDE · Infosys OA
Problem: How many palindromic substrings does "aabbaa" contain? Two substrings count as different if they occupy different index ranges, even when their letters match.
- A. 11
- B. 6
- C. 5
- D. 21
Correct answer: A. 11
Single letters give 6, the length-2 matches aa, bb, aa give 3, abba gives 1 and aabbaa gives 1, for 11 occurrences. Counting distinct palindromic strings merges the repeats (6), skipping single letters gives 5, and 21 counts every substring.
More Coding Interview Problems questions
- Problem: Compute the KMP prefix function (the longest proper prefix that is also a suffix, for each prefix) of the pattern "abacabab"…
- Problem: Count the occurrences of the pattern "aaa" in the text "aaabaaaab", where occurrences may overlap (each starting index that…
- Problem: Round-robin scheduling with time quantum 3 is applied to processes that all arrive at time 0: P1 needs 7 units, P2 needs 4, P3…
- Problem: Josephus game: n = 37 people stand in a circle numbered 1 to 37. Starting from person 1, every 4th person is removed (counting…
- Problem: A deque starts empty. Operations in order: pushback(5), pushfront(2), pushback(8), popfront(), pushfront(9), pushback(1)…
- Problem: How many integers x in the range 1 ≤ x ≤ 1000 have exactly 4 set bits in their binary representation?