Ad
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    The definition of this problem can be improved. By the current definition, next() returns 1 and prev() returns 5 given the first example of [1..5]. This implies that the pointer is "between" the last and first elements, a state it will never find itself in again. This makes the solution more convoluted and difficult to reason about.

    I suggest specifying that in the initial state next() returns 2 and prev() returns 5. Alternatively, if next() returns 1, prev() can return 4.

    Another option is to take the initial "selected element" as input in the constructor.