Browser History

    0

    0

    Mansimar Anand

    Browser History

    class BrowserHistory {
    public:
        int index;
        vector<string> list;
        BrowserHistory(string homepage) {
            index = 0;
            list = {homepage};
        }
        void visit(string url) {
            while(index+1 != list.size()) {
                list.pop_back();
            }
            ++index;
            list.emplace_back(url);
        }
        string back(int steps) {
            index = max(0, index - steps);
            return list[index];
        }
        string forward(int steps) {
            index = min((int)list.size() - 1, index + steps);
            return list[index];
        }
    };
    /**
     * Your BrowserHistory object will be instantiated and called as such:
     * Your BrowserHistory object will be instantiated and called as such:
     * BrowserHistory* obj = new BrowserHistory(homepage);
     * BrowserHistory* obj = new BrowserHistory(homepage);
     * obj->visit(url);
     * obj->visit(url);
     * string param_2 = obj->back(steps);
     * string param_2 = obj->back(steps);
     * string param_3 = obj->forward(steps);
     * string param_3 = obj->forward(steps);
     */
     */
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.