One Vector | Clean and Intuitive Code with Explanation
\n\nSteps:\n\n Initialise a vector to store all the URLs that you visit and a current variable to denote index of current url in vector\n Push homepage in vecto
<br/>\n\n**Steps:**\n\n* Initialise a vector to store all the URLs that you visit and a current variable to denote index of current url in vector\n* Push homepage in vector and make it current\n* The tricky part is implementing Visit function **you have to clear the forward history in visit function** , so erase all the urls after current url and push the new url and make it current\n* You can go at max `current - steps` steps back, so make it current and return that url\n* You can go at max `urls.size() - current - 1` steps forward, so make it current and return that url\n<br/>\n\n```\nclass BrowserHistory {\npublic:\n    \n    vector<string> urls;\n    int current;\n    \n    BrowserHistory(string homepage) {\n        urls.push_back(homepage);  \n        current = 0;\n    }\n    \n    void visit(string url) {\n        urls.erase(urls.begin() + current + 1, urls.end());\n        urls.push_back(url);\n        current++;\n    }\n    \n    string back(int steps) {\n        current = max(0, current - steps);\n        return urls[current];\n    }\n    \n    string forward(int steps) {\n        current = min((int)urls.size() - 1, current + steps);\n        return urls[current];\n    }\n};\n```\n<br/>\nDo upvote if you liked the code and explanation :)\n<br/>
['C', 'C++']