Java || Runtime 136 ms Beats 6.57% Memory 50.9 MB Beats 13.15%
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass BrowserHistory {\n    Stack<String> bStack = new Stack<>();\n    Stack<String> fStack = new Stack<>();\n    public BrowserHistory(String homepage) {\n        bStack.push(homepage);\n    }\n    \n    public void visit(String url) {\n        while(!fStack.isEmpty()) fStack.pop();\n        bStack.push(url);\n\n    }\n    \n    public String back(int steps) {\n        while(bStack.size()>1 && steps-- > 0){\n           fStack.push(bStack.peek());\n           bStack.pop();\n        }\n        return bStack.peek();\n        }\n    \n    \n    public String forward(int steps) {\n        while(!fStack.isEmpty() && steps-- > 0){\n            bStack.push(fStack.peek());\n            fStack.pop();\n        }\n        return bStack.peek();\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```
['Java']