Python - Two Stacks
Use a back stack for navigating back and use forward stack for navigating forward.\n\npy\n\nclass BrowserHistory:\n\n    def __init__(self, homepage: str):\n   
Use a back stack for navigating back and use forward stack for navigating forward.\n\n```py\n\nclass BrowserHistory:\n\n    def __init__(self, homepage: str):\n        self.back_stack = [homepage]\n        self.forward_stack = []\n\n    def visit(self, url: str) -> None:\n        self.forward_stack.clear() \n        self.back_stack.append(url)\n\n    def back(self, steps: int) -> str:\n        while len(self.back_stack) >= 2 and steps > 0:\n            top = self.back_stack.pop()\n            self.forward_stack.append(top)\n            steps -= 1\n        return self.back_stack[-1]\n\n    def forward(self, steps: int) -> str:\n        while len(self.forward_stack) > 0 and steps > 0:\n            top = self.forward_stack.pop()\n            self.back_stack.append(top)\n            steps -= 1\n        return self.back_stack[-1]\n\n\n```
[]