Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA
How many palindromic substrings of length at least 3 does "racecarxyzzyx" contain (counted by position)?
- A. 6
- B. 4
- C. 5
- D. 7
Correct answer: C. 5
Enumerate all substrings of length at least 3 and test each for palindromicity. Including length-1 and length-2 palindromes (not required here) changes the count.
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 each value n in [10, 27, 50], count the positive integers x with x^3 <= n, then add the three counts. What is the total?
- How many adjacent positions in [3, 9, 4, 7, 1] have a[i] > a[i+1]?
- What is the minimum number of characters that must be inserted at the front of "abcdc" to make it a palindrome?
- Remove exactly one element from [5, -4, 3, -7, 2], then take the maximum product of two distinct remaining elements. What is that maximum…
- How many starting positions in "abcbabcab" match the pattern "abc" with exactly one mismatched character?
- How many substrings of length 2 of "abcba" read the same forwards and backwards?