Ad
  • 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.

  • Custom User Avatar
  • Default User Avatar

    Java:

    • tests emit warnings to STDERR:
      Note: src/test/java/Tests.java uses unchecked or unsafe operations.

      because of this line:

      public void emptyListTest() {
        new CircularList();
      }
      

      (CircularList is a raw type and needs to be parameterized).

    • Your list constructor/init code should throw an Exception if nothing is passed in.

      is really misleading, since literally throwing a new Exception() does not compile, as it is a checked exception and the tests do not catch it.

    • In the initial code, the constructor of CircularList should probably be annotated with @SafeVarargs to avoid a warning.

  • Custom User Avatar