Find earliest time password becomes irrecoverable
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Online Assessment
Overview: This question evaluates understanding of combinatorics, string processing, and algorithmic data structures for efficiently tracking dynamic intervals and counting contiguous substrings as characters are corrupted over time.
Constraints
- 1 <= n <= 8e5
- password consists of lowercase English letters
- attack_order is a permutation of 1..n (1-indexed positions)
- 0 <= m <= n*(n+1)/2
- Return the minimal t in [1..n]; if m == 0, return 1
Hints
- The number of substrings containing '*' is non-decreasing over time; use binary search on t.
- For a fixed t, positions attacked by time t split the array into clean segments; substrings without '*' are the sum over segments of len*(len+1)/2.
- Precompute the attack time for each position to check any t in O(n).