Swift | Two Stacks
Two Stacks (accepted answer)\n\nclass BrowserHistory {\n    var history = [String]()\n\tvar future  = [String]()\n    \n    init(_ homepage: String) {\n        
**Two Stacks (accepted answer)**\n```\nclass BrowserHistory {\n    var history = [String]()\n\tvar future  = [String]()\n    \n    init(_ homepage: String) {\n        visit(homepage)\n    }\n    \n    func visit(_ url: String) {\n        future = []\n        history.append(url)\n    }\n    \n    func back(_ steps: Int) -> String {\n        for i in 0 ..< min(steps, history.count-1) {\n            future.append(history.last!)\n            history.removeLast()\n        }\n        return history.last!\n    }\n    \n    func forward(_ steps: Int) -> String {\n        for i in 0 ..< min(steps, future.count) {\n            history.append(future.last!)\n            future.removeLast()\n        }        \n        return history.last!\n    }\n}\n```
['Swift']