Kotlin
Thank you for upvoting.\n\n\nclass BrowserHistory(homepage: String) {\n\n  private val chain = mutableListOf<String>(homepage)\n  private var idx = 0\n\n  fun v
Thank you for upvoting.\n\n```\nclass BrowserHistory(homepage: String) {\n\n  private val chain = mutableListOf<String>(homepage)\n  private var idx = 0\n\n  fun visit(url: String) {\n    while (idx != chain.size - 1)\n      chain.removeAt(chain.size - 1)\n    chain.add(url)\n    idx++\n  }\n\n  fun back(steps: Int): String {\n    idx = maxOf(idx - steps, 0)\n    return chain[idx]\n  }\n\n  fun forward(steps: Int): String {\n    idx = minOf(chain.size - 1, idx + steps)\n    return chain[idx]\n  }\n\n}\n\n```
['Kotlin']