Java, one List and a pointer, O(1) time
\nclass BrowserHistory {\n    \n    List<String> history;\n    int last=-1;\n    int cur=-1;\n    public BrowserHistory(String homepage) {\n        history=new 
```\nclass BrowserHistory {\n    \n    List<String> history;\n    int last=-1;\n    int cur=-1;\n    public BrowserHistory(String homepage) {\n        history=new ArrayList<>();\n        history.add(homepage);\n        last=0;\n        cur=0;\n    }\n    \n    public void visit(String url) {\n        last=cur+1;\n        if(history.size()==last) history.add(url);\n        else history.set(last,url);\n        cur=last;\n    }\n    \n    public String back(int steps) {\n        int first=Math.max(0,cur-steps);\n        cur=first;\n        return history.get(first);\n    }\n    \n    public String forward(int steps) {\n        int l=Math.min(last,cur+steps);\n        cur=l;\n        return history.get(l);\n    }\n}\n```
[]