Data Structures & AlgorithmsModerateProduct Company SDE · Amazon/Microsoft-style OA
Problem: Find the length of the longest palindromic substring of the string "abacdfgdcabazyx".
- A. 4
- B. 2
- C. 3
- D. 5
Correct answer: C. 3
Expanding around every centre (both odd and even) finds the longest palindrome in O(n²). Only centre-expansion for odd lengths would miss even ones like 'aa' inside a longer string.
More Coding Interview Problems questions
- Problem: Using insert, delete and replace, each costing 1, what is the minimum number of operations to convert "dragon" into "lantern"?
- Problem: How many palindromic substrings does "aabbaa" contain? Two substrings count as different if they occupy different index ranges…
- 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…