c++|| beat 100% || intuition + approch || easy || vector
Intuition\nWe have perform simple task of return some index value (string) of some data structure in call of back and forword.\n\n=>> simplest way to return val
# Intuition\nWe have perform simple task of return some index value (string) of some data structure in call of back and forword.\n\n=>> simplest way to return value of any index in most efficiet manner\n can be done in vector if we have known of index.\n\n=>> In visit we need to remove some element from last , that also can be done in vector easly.\n\n=>> from above observation we came to use vector as our data structure.\n\n# Approach\n=>> While moving forword or back we just need to , are we not going out of index ,\n **if we going out of index.....**\n\n=>> In case of **back**  we have to stop on index no 0 , set index =0\n\n=>> In case of **forword** , we have stop on size of vector , set index = vector.size()-1.\n\n=>> In case of **visit** , we hace to pop out all the element having index greater than or equal to our current index, At which pointing.\n\n**IF YOU READ IT LET ME KNOW BY UP VOTE IT !!**\n\n***GOT THE INTUITION AND APPROCH ? UPVOTE : IGNORE.***\n\n# Complexity\n- Time complexity:\n=>> For back = O(1)\n=>> for forword O(1)\n=>> visit O(n) in worse case.\n\n- Space complexity:\nO(n) Need to store data atlest. ( mota moti space complexcity)\n\n# Code\n```\n#define pb push_back\nclass BrowserHistory {\npublic:\n    int ele;\n    vector<string> vc;\n    BrowserHistory(string homepage) {\n        vc.pb(homepage);\n        ele  =0;\n    }\n    \n    void visit(string url) {\n        int l = vc.size()-1;\n        while(l>ele){\n            vc.pop_back();\n            l--;\n        }\n        ele++;\n        vc.pb(url);\n    }\n    \n    string back(int steps) {\n        ele-=steps;\n        if(ele<0) ele=0;\n        return vc[ele];\n    }\n    \n    string forward(int steps) {\n        ele +=steps;\n        if(ele>=vc.size()) ele = vc.size()-1;\n        return vc[ele];\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```
['C++']