Which data structure is used when we click on the back arrow in a browser?
Asked in the Technical + HR interview stage. Candidate answered Stack.
Implement browser navigation using a back stack and a forward stack. Given an initial page and actions, return the current page after each action. A URL string represents navigation to a new page. The commands BACK and FORWARD move through history when possible. Navigating to a new page clears forward history.
Function: def process_history(initial_page, actions):
Input: A string and a list of strings. Output: A list of current-page strings.
def process_history(initial_page, actions):