Java O(1) for all methods
we use nodes to store the data, use a map to save the index to node, and save rightIndex and currentIndex\n\nback(): \n\tget the new currentIndex and use the ma
we use nodes to store the data, use a map to save the index to node, and save rightIndex and currentIndex\n\nback(): \n\tget the new currentIndex and use the map to get the node, notice the rightIndex value isnt changed here\nvisit(): \n\tmove currentIndex forward 1 step and make the rightIndex the value of the currentIndex since we\'re overriding\n\tnotice here that we aren\'t updating the latter values in the map so the map will have extra data, but this isn\'t a big deal \n\tas we never access it, and we just end up overwriting it when we add more visits, we don\'t want to delete the data\n\tbecause then the solution will no longer be O(1)\nforward():\n\there we just move forward with max at the rightindex\n\n\n```\nclass BrowserHistory {\n    \n    Node head;\n    Node current;\n    int currentIndex;\n    Map<Integer, Node> map;\n    int rightIndex;\n\n    public BrowserHistory(String homepage) {\n        head = new Node(homepage);\n        current = head;\n        currentIndex = 0;\n        map =new HashMap<>();\n        map.put(0, head);\n        rightIndex = 0;\n    }\n    \n    public void visit(String url) {\n        currentIndex++;\n        current.right = new Node(url);\n        current = current.right;\n        map.put(currentIndex, current);\n        rightIndex = currentIndex;\n    }\n    \n    public String back(int steps) {\n        currentIndex = currentIndex - steps >= 0 ? currentIndex - steps : 0;\n        current = map.get(currentIndex);\n        return current.value;\n    }\n    \n    public String forward(int steps) {\n        currentIndex = currentIndex + steps <= rightIndex ? currentIndex + steps : rightIndex;\n        current = map.get(currentIndex);\n        return current.value;\n    }\n}\n\nclass Node {\n    String value;\n    Node left;\n    Node right;\n    \n    public Node(String value){\n        this.value = value;\n    }\n}\n\n/**\n * Your BrowserHistory object will be instantiated and called as such:\n * BrowserHistory obj = new BrowserHistory(homepage);\n * obj.visit(url);\n * String param_2 = obj.back(steps);\n * String param_3 = obj.forward(steps);\n */\n```
['Java']