Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA
How many distinct non-empty substrings does the string "abacaba" have?
- A. 22
- B. 28
- C. 21
- D. 19
Correct answer: C. 21
Count distinct strings, not positions. Equal substrings at different positions are counted once, so the answer is well below the 28 positional substrings.
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
- In the string "ababababa", how many times does "aba" occur, counting overlapping occurrences?
- For the string "aabaaab", what is the last value of the KMP prefix-function (the length of the longest proper prefix that is also a suffix…
- What is the smallest period p (1 <= p < n) of the string "abcabcabca" such that s[i] = s[i + p] for all valid i?
- Using the standard convention z[0] = 0, what is the sum of the Z-function values z[1] through z[6] of the string "aaabaab"?
- What is the area of the largest rectangle that fits in the histogram with bar heights [2, 1, 5, 6, 2, 3]?
- What is the minimum number of swaps of ANY two (not necessarily adjacent) elements needed to sort the permutation [4, 3, 2, 1] into…