title: Moving character efficiently on a row
body: <p>Given input <code>(items = 6, position = 3)</code></p>
  <p>creates a row of <code>6 items</code> and a character positioned on <code>item 3</code> <code>{0,1,2,[3],4,5}</code></p>
  <p>A call to <code>left()</code> moves the character <strong>two</strong> positions to the left and the <code>item at position 3 is removed</code> <code>{0,[1],2,4,5}</code></p>
  <p>The next call to <code>right()</code> moves the character two positions to the right and the <code>item at position 1 is removed</code> <code>{0,2,[4],5}</code></p>
  <p>Then calling <code>position()</code> method now should return <code>4</code>.</p>
  <p>The character will not move to the left or right if no items are present so no need to implement that.</p>
  <pre><code>public class MyClass {
      int position;
      int[] items;
      public MyClass(int n, int position) {
          this.position = position;
          items = new int[n];
          for(int i=0; i&lt;n; i++) {
              items[i] = i;
          }
      }
  }
  
  public void left() {
      int p = this.position;
      items[p] = -1;
      for(int z=0; z&lt;2;) {
          p--;
          int value = arr[p];
          if(value != -1) {
              z++;
          }
      }
      this.position = p;
  }
  
  public void right() {
      int p = this.position;
      items[p] = -1;
      for(int z=0; z&lt;2;) {
          p++;
          int value = arr[p];
          if(value != -1) {
              z++;
          }
      }
      this.position = p;
  }
  
  public int position() {
      return arr[position];
  }
  </code></pre>
  <p>This code works perfectly for small inputs, but I am getting performance errors when the input is large.</p>
  <p>How to implement this efficiently? I don't have test case details for the error related to performance errors.</p>