Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: Compute the longest palindromic prefix of "abacabacaba" (the longest prefix that reads the same backwards). What is its length?
- A. 7
- B. 3
- C. 11
- D. 1
Correct answer: C. 11
"abacabacaba" equals its reverse, so the whole string of length 11 is the answer. Looking only at proper prefixes gives "abacaba" (7), stopping at "aba" gives 3, and 1 is a single letter.
More Coding Interview Problems questions
- Problem: What is the length of the longest common substring (contiguous) of "abcdxyz" and "xyzabcd"?
- Problem: From the array [3, 2, 7, 10], choose a subset with no two adjacent indices chosen, maximising the sum. What is the maximum sum?
- Problem: The array [5, 1, 6, 2, 7] must be made strictly increasing by deleting the fewest elements. What is the minimum number of…
- Problem: On the complete graph K4 (vertices 0–3, every pair adjacent), how many walks of exactly 4 edges start at vertex 0? A walk may…
- Problem: Lomuto partition uses the last element as the pivot on [3, 8, 2, 5, 1, 4, 7, 6]. After one partition pass, at what index…
- Problem: Five numbers 1, 2, 3, 4, 5 are inserted in that order into an initially empty min-heap (array form, sift-up after each…