✅$$O(1)$$🔥||✅99.73%🔥||✅Array Approach||🔥Easy to understand||✅4 Simple Steps
Approach:\nInit: Define an array, initally with value homepage.\nVisit: Check if it\'s a new site, if so append. If not set it as a new site and delete the rest
**Approach:**\nInit: Define an array, initally with value *homepage*.\nVisit: Check if it\'s a new site, if so append. If not set it as a new site and delete the rest.\nBack: Move the index back and check out of bounds errors. Return the string.\nForward: Move the index forward and also check out of bounds. Return the string.\n\n---\n**Complexity:**\n* Time complexity: O(1)\n\n* Space complexity: O(n)\n\n*Because we used an array indexing is a constant time operation.\n*Also appending is constant because on average it is still O(1) and not the worst case O(n)!\n\n---\n**Code:**\n```\nclass BrowserHistory:\n\n    def __init__(self, homepage: str):\n        self.nums: list(str) = [homepage]\n        self.index: int = 0\n\n    def visit(self, url: str) -> None:\n        if self.index == len(self.nums)-1:\n            self.nums.append(url)\n            self.index += 1\n        else:\n            self.index += 1\n            self.nums[self.index] = url\n            self.nums = self.nums[:self.index+1]\n\n    def back(self, steps: int) -> str:\n        self.index -= steps\n        if self.index < 0:\n            self.index = 0\n        return self.nums[self.index]\n\n    def forward(self, steps: int) -> str:\n        n: int = len(self.nums)-1\n        self.index += steps\n        if self.index > n:\n            self.index = n\n        return self.nums[self.index]\n```\n\n---\n![image](https://assets.leetcode.com/users/images/bf01ce7e-78d5-4ab5-a73c-afacf6a9a548_1728377376.489099.png)\n\n---\nIf you have any suggestions, let me know!\n**Litterally you after upvoting:**\n![image](https://assets.leetcode.com/users/images/e353c482-302e-47cc-9b20-d5bd6ce98122_1727619673.744064.jpeg)\n\n\n---
['Array', 'Python', 'Python3']