Data Structures & AlgorithmsHardGATE CS · ICPC regional
Which algorithm finds the longest palindromic substring of a string in linear time?
- A. Dijkstra's algorithm
- B. Kruskal's algorithm
- C. Manacher's algorithm
- D. Bellman-Ford algorithm
Correct answer: C. Manacher's algorithm
Manacher's algorithm reuses palindrome radii from a mirrored centre to achieve O(n). The other three are graph algorithms, unrelated to strings.
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
- Which technique detects whether an array contains a non-empty subarray with sum zero in O(n) expected time?
- An array of 200000 integers may contain negative values, and you must count its contiguous subarrays whose sum equals K in near-linear…
- For a string of length 10^6 and a pattern of 20 letters, you need the shortest substring containing every pattern letter with…
- Given an array of 10^6 values and window size k, you need the maximum over all windows of the window minimum. What is the most suitable…
- How many contiguous subarrays of [1, 2, 1, 3, 2, 2, 1] contain at most two distinct values?
- You may increase any element of [2, 5, 3, 9] by 1 per operation, and you want all elements equal. What is the minimum number of operations?