Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: The string "aaaa" has how many distinct palindromic substrings (counting each distinct string once, of any length ≥ 1)?
- A. 5
- B. 4
- C. 3
- D. 6
Correct answer: B. 4
All substrings of a run of equal letters are palindromes, so the distinct ones are a, aa, aaa and aaaa. Counting index ranges instead gives 10.
More Coding Interview Problems questions
- Problem: In the tree with edges 1-2, 1-3, 2-4, 2-5, 3-6, 3-7, what is the number of leaves (nodes with degree 1)?
- Problem: The subset-sum DP over the values [2, 3, 7, 8, 10] asks: how many subsets have sum exactly 11? The empty subset has sum 0 and is…
- Problem: The array [10, 20, 30, 40, 50] is searched for the first index i whose value is strictly greater than the average of all elements…
- Problem: Bob has the numbers 1 to 10 written on a board. He repeatedly erases the two largest numbers and writes their difference. After 9…
- Problem: The string "racecar" is compressed by storing each character and the number of distinct palindromic substrings of length at least…
- Problem: What is the sum of all integers below 1000 that are multiples of 3 or 5? Run the code. python print(sum(x for x in range(1000) if…