Data Structures & AlgorithmsVery hardProduct placement · Amazon/Microsoft
What is the minimum number of characters that must be APPENDED to the end of "abacdcab" to make it a palindrome? (Find the longest palindromic suffix, e.g. with KMP on reverse(s) + '#' + s.)
- A. 2
- B. 5
- C. 1
- D. 7
Correct answer: C. 1
The longest suffix that is already a palindrome is "bacdcab"; the 1 characters before it must be mirrored onto the end. Prepending would instead need 5 characters.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- For [7, 3, 5, 3, 7, 2, 5], definition A returns the element whose FIRST occurrence is earliest among all repeating elements; definition B…
- nums1 = [2, 5, 8, 0, 0, 0] (3 real values plus 3 buffer slots) and nums2 = [3, 6, 9] are merged in place by filling nums1 from the BACK…
- What is the sum of the minimum value of every contiguous window of length 3 in the array [4, 2, 12, 11, -5, 3, 7]?
- For each index i, let di be (index of the nearest element to the right that is strictly greater than a[i]) minus i, or 0 if no such…
- How many permutations of 1, 2, 3, 4, 5 can be sorted into increasing order by a single stack, where each input element is pushed in order…
- In the Josephus game, 41 people stand in a circle numbered 1 to 41. Starting from person 1, every 3rd person is removed (counting…