Amazon Alexa SDE Hiring Challenge
Good String
Good String
You are given a string S of length N, Q ranges of the form [L, R] in a @D array range, and a permutation arr containing numbers from 1 to N.
Task
In one operation, you remove the first unremoved character as per the permutation. However, the positions of other characters will not change. Determine the minimum number of operations for the remaining string to be good.
Notes
- A string is considered good if all the Q ranges have all distinct characters. Removed characters are note counted.
- A range with all characters removed is considered to have all distinct characters.
- The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.
- 1-based indexing is followed.
Solution
- Time : O(logn * (n + qlogn))
- Space : O(n)
c++
1 |
|