Company: Amazon

Difficulty: medium

Problem Statement

# Binary Command Autocomplete An old motor-controller console receives binary command strings. When a new command is entered, the console displays one previously entered command according to these rules: 1. Choose a previous command having the longest common prefix with the new command. 2. If several previous commands tie, choose the most recently entered one. 3. If no previous command shares a non-empty prefix, choose the most recent previous command. 4. For the first command, display nothing. For every command, output the 1-based index of the command displayed by autocomplete, or `0` when no previous command exists. ## Input Format - The first line contains `N`. - Each of the next `N` lines contains one non-empty binary command. ## Output Format Print `N` space-separated integers. ## Constraints - `1 <= N <= 200000` - Every command contains only `0` and `1`. - The total length of all commands is at most `200000`. ## Example Input: 6 0000 1110 01 0001 110 11 Output: 0 1 1 1 2 5

More Amazon OA questionsInterview experiences