Data Structures & AlgorithmsHardProduct Company SDE · Amazon OA
Problem: How many distinct palindromic substrings does "abacaba" contain (single characters count as palindromes, and distinct strings count once)?
- A. 12
- B. 4
- C. 7
- D. 3
Correct answer: C. 7
The distinct palindromes are a, b, c, aba, aca, bacab and abacaba: 7. Counting occurrences instead gives 12, leaving out single letters gives 4, and counting only the single letters gives 3.
More Coding Interview Problems questions
- Problem: Among all distinct permutations of the letters A, B, C, D, arranged in dictionary order starting from rank 1, what is the rank of…
- Problem: For the words ["flowchart", "flow", "flight", "flower"], what is the length of their longest common prefix?
- Problem: In the string "abciiidef", what is the maximum number of vowels (a, e, i, o, u) in any contiguous substring of length 4?
- Problem: What is the minimum number of insertions plus deletions needed to convert "heap" into "pea" if only insertions and deletions are…
- Problem: How many binary strings of length 8 have no two consecutive 1s and begin with the digit 0?
- Problem: A 0/1 knapsack has capacity 10 and items (weight, value): (5, 10), (4, 40), (6, 30), (3, 50). What is the maximum total value?