C++ solution using Doubly Linked List
IntuitionApproachThis implementation uses a doubly linked list to manage the browser history:Node Structure:
Each node stores a URL along with pointers to the p
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
This implementation uses a doubly linked list to manage the browser history:

Node Structure:
Each node stores a URL along with pointers to the previous and next nodes.

Constructor:
The BrowserHistory constructor initializes the list with the homepage as the first node.

visit(string url):
When a new URL is visited, a new node is created, linked to the current node, and then set as the current node. This automatically discards any forward history.

back(int steps):
Moves the current pointer backwards up to the specified steps (or until no previous node exists) and returns the URL at the current node.

forward(int steps):
Moves the current pointer forward up to the specified steps (or until no next node exists) and returns the URL at the current node.
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity: O(N)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(N)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class BrowserHistory {
public:
    struct Node{
        string url;
        Node* next;
        Node* prev;

        Node(string url): url(url),next(NULL),prev(NULL){}

    };
    Node* curr;
    BrowserHistory(string homepage) {
        curr=new Node(homepage);
    }
    
    void visit(string url) {
        Node* newNode=new Node(url);
        curr->next=newNode;
        newNode->prev=curr;
        curr=newNode;
    }
    
    string back(int steps) {
        while(steps-- > 0 && curr->prev){
            curr=curr->prev;
        }
        return curr->url;
    }
    
    string forward(int steps) {
        while(steps-- > 0 && curr->next){
            curr=curr->next;
        }
        return curr->url;
    }
};

/**
 * Your BrowserHistory object will be instantiated and called as such:
 * BrowserHistory* obj = new BrowserHistory(homepage);
 * obj->visit(url);
 * string param_2 = obj->back(steps);
 * string param_3 = obj->forward(steps);
 */
```
['C++']