Company: Zomato_21july
Difficulty: medium
Binary Autocomplete Problem Description Given a console for an old motor controller that accepts binary string commands, implement its autocomplete feature. The autocomplete works as follows: When typing a new command, it displays the previously entered command with the longest common prefix. If multiple previous commands share the same longest prefix, display the most recent one. If no previous command shares a common prefix, display the most recent command. If there are no previous commands, display nothing. Write a function that takes a sequence of commands and returns an array where each element is the index of the command displayed by autocomplete for each new command. Return 0 if there is no previous command. Examples Example 1: n = 6 command = ['000', '110', '01', '001', '110', '11'] The return array is [0, 1, 1, 2, 5]. Explanation: '000' - 0 (No command has previously been entered) '110' - 1 (There is no previous command that shares a common prefix, so the last command is shown