PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick 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.

  • medium
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Find earliest time password becomes irrecoverable

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

You are given a password string of length n and an attack order array attackOrder[1..n], a permutation of 1..n. At second i (1-indexed), the virus replaces the character at position attackOrder[i] with a malicious character '*'. A substring is contiguous. The password becomes irrecoverable when the number of substrings containing at least one '*' is >= m. Find the minimum time t (1 <= t <= n) after which the password is irrecoverable. Special rule: if the password is considered irrecoverable at the start, report 1. Constraints: 1 <= n <= 8e5; password is lowercase letters; 1 <= attackOrder[i] <= n; 0 <= m <= n*(n+ 1)/2.

Quick Answer: 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.

You are given a password string of length n and an array attack_order[1..n], a permutation of 1..n. At second i (1-indexed), the character at position attack_order[i] is replaced by '*'. A substring is contiguous. The password is irrecoverable when the number of substrings containing at least one '*' is at least m. Find the minimum t (1 <= t <= n) such that after t seconds the password is irrecoverable. Special rule: if m == 0, return 1.

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

  1. The number of substrings containing '*' is non-decreasing over time; use binary search on t.
  2. 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.
  3. Precompute the attack time for each position to check any t in O(n).
Last updated: Mar 29, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Minimum Path Length Through a Grid With One Allowed Cell Conversion - Amazon (medium)
  • Circular Drone Hub Delivery Route - Amazon (hard)
  • Leaf Domain Cumulative Scores - Amazon (medium)
  • Kth Largest Perfect Binary Subtree - Amazon (medium)
  • Find Conflicting Events - Amazon (medium)