Find minimum time for irrecoverable password
AmazonSoftware Engineer · Online AssessmentLast updated
This question evaluates string-processing skills, combinatorial counting of substrings, simulation of time-based state changes, and algorithmic complexity analysis.
A password is a string s of length n. A virus attacks positions in a 1-indexed order given by a permutation attackOrder[1..n]. At second t (1 <= t <= n), the character at position attackOrder[t] is replaced by a malicious character ''. The password is irrecoverable once the number of substrings containing at least one '' is >= m. Find the minimum time t after which the password becomes irrecoverable; if it is irrecoverable at the start, return 1. Implement findMinimumTime(password, attackOrder, m) and state the algorithm and its time and space complexity.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.