The easiest Java solution.
Intuition\nThe easiest solution. You need only ArraList (for fast retriving browser history and creating sublist) and value for the current pointer.\n\n# Approa
# Intuition\nThe easiest solution. You need only ArraList (for fast retriving browser history and creating sublist) and value for the current pointer.\n\n# Approach\nUse **current** to store current index. \n- If you visit a new site, just increment it. \n- If you go back just check that current + steps less that browser history. If is true, set current = current + steps. If not, set current = 0 (this is your homepage). \n- If you go forward do the opposite.\n\nUse **history list** to store browser history.\n- If you visit a new site and your pointer in the middle of the browser history, *you must remove all values on the ride side of history*, because the new site should be the last in the history of the browser. I chose sublist(), but you can find something more efficient. \n\n\n# Code\n```\nclass BrowserHistory {\n  private int current;\n  private List<String> history = new ArrayList<>();\n\n  public BrowserHistory(String homepage) {\n    history.add(homepage);\n    current = 0;\n  }\n\n  public void visit(String url) {\n    history.add(++current, url);\n    if (current < history.size() - 1)\n      history = history.subList(0, Integer.min(current + 1, history.size() - 1));\n  }\n\n  public String back(int steps) {\n    current = Math.max(current - steps, 0);\n    return history.get(current);\n  }\n\n  public String forward(int steps) {\n    current = Math.min(current + steps, history.size() - 1);\n    return history.get(current);\n  }\n}\n```\n**If you like my solution, please, upvote it.**
['Java']