Data Structures & AlgorithmsHardGATE CS · Infosys
What is the length of the longest prefix of the string ababbaba that is itself a palindrome?
- A. 7
- B. 3
- C. 1
- D. 8
Correct answer: D. 8
Check prefixes against their reverse from the longest: 'ababbaba' reversed is 'ababbaba', so the whole string (8) is a palindrome. Stopping at the first palindromic prefix after 'a' gives 3 (aba), 1 is the trivial prefix and 7 assumes the full string cannot qualify.
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
- An LRU cache of capacity 2 receives the request sequence 2, 1, 2, 3, 1, 2. A request is a hit if its key is cached. How many hits occur?
- How many integers i with 1 <= i <= 50 have i i mod 10 = 9?
- How many integers in the range 1 to 100 are coprime to 30 (that is, gcd(x, 30) = 1)?
- How many pairs of distinct array positions i < j in [1, 2, 3, 4, 5, 6, 9] have a[i] a[j] divisible by 6?
- What is the total number of distinct values obtained by summing two different elements of [1, 2, 3, 4] (order does not matter)?
- How many substrings of length 2 in the string abcabcab occur at least twice in the string (possibly overlapping)?