Easy JS solution Using DLL || Beats 89% online submissions
By using Node\n\nWe will create a Node class. Each node in the linked list represents a visited URL, and has a "val" (URL string), "prev" (previous node) and "n
# **By using Node**\n\nWe will create a Node class. Each node in the linked list represents a visited URL, and has a "val" (URL string), "prev" (previous node) and "next" (next node) field.\n\nThe "visit" method adds a new URL to the history by creating a new node and setting its "prev" field to the current "root" node, and the "next" field of the current "root" node to the new node. The "root" variable is then updated to point to the new node.\n\nThe "back" method navigates the history backward by following the "prev" pointers of nodes until the desired number of steps is reached, or until the beginning of the history is reached. The "root" variable is then updated to point to the current node, and its "val" field is returned.\n\nThe "forward" method navigates the history forward by following the "next" pointers of nodes until the desired number of steps is reached, or until the end of the history is reached. The "root" variable is then updated to point to the current node, and its "val" field is returned.\n\n# By using List\n\nThe current URL is represented by the index "curr", which starts at 1 (since the first visited URL is at index 0). The total number of visited URLs is stored in the "total" variable.\n\nThe "visit" method adds a new URL to the history by either setting the element at index "curr" to the new URL (if there are already visited URLs after the current position), or by adding the new URL to the end of the list. The "curr" and "total" variables are updated accordingly.\n\nThe "back" method navigates the history backward by decrementing "curr" by the specified number of steps, but ensuring that it never goes below 1 (the beginning of the history). The URL at index "curr-1" is then returned.\n\nThe "forward" method navigates the history forward by incrementing "curr" by the specified number of steps, but ensuring that it never goes above the "total" number of visited URLs. The URL at index "curr-1" is then returned.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(1)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(N)\n# Code\n```\nclass BrowserHistory {\n    \n    constructor(homepage) {\n        this.history = [homepage];\n        this.curr = 0;\n        this.limit = 0;\n    }\n    \n    visit(url) {\n        this.curr++;\n        if(this.curr == this.history.length) this.history.push(url);\n        else this.history[this.curr] = url;\n        this.limit = this.curr;\n    }\n    \n    back(steps) {\n        this.curr = Math.max(0, this.curr-steps);\n        return this.history[this.curr];\n    }\n    \n    forward(steps) {\n        this.curr = Math.min(this.limit, this.curr+steps);\n        return this.history[this.curr];\n    }\n}\n```
['Linked List', 'Design', 'Doubly-Linked List', 'Data Stream', 'JavaScript']