Python3 || Simplest solution using list (array) and two pointers || 99% faster || O(1)
The solution is using a list (array) and two pointers (current and end) to maintain states.\nConstraint was max calls altogether is 5000. So maximum calls of vi
The solution is using a list (array) and two pointers (current and end) to maintain states.\nConstraint was max calls altogether is 5000. So maximum calls of visit is 5000 plus one __init__ in worst case. So maximum urls that can be there in one test case in 5001.\n\nJust my manipulating 2 pointers (current and end), we can do back(steps) and forward(steps) operation in O(1). Visit(url) operation is also O(1).\n\n**Kindly upvote if you like the simplest and easy solution.**\n\n\'\'\'\nclass BrowserHistory:\n\n    def __init__(self, homepage: str):\n        self.urlarr = [None]*5001\n        \n        self.curr = 0\n        self.end = 0\n        self.urlarr[self.curr] = homepage\n\n    def visit(self, url: str) -> None:\n        # print(self.curr,self.end,url)\n        self.curr+=1\n        self.urlarr[self.curr] = url\n        self.end = self.curr\n\n    def back(self, steps: int) -> str:\n        if self.curr - steps <= 0:\n            self.curr = 0\n            return self.urlarr[0]\n        else:\n            self.curr = self.curr - steps\n            return self.urlarr[self.curr]\n\n    def forward(self, steps: int) -> str:\n        if self.curr + steps >= self.end:\n            self.curr = self.end\n            return self.urlarr[self.end]\n        else:\n            self.curr = self.curr + steps\n            return self.urlarr[self.curr]\n\'\'\'
['Python', 'Python3']