title: Check if a circular path exists given a string input as a list of moves
body: <p>This is a similar question to <a href="https://leetcode.com/problems/robot-bounded-in-circle/" rel="nofollow noreferrer">https://leetcode.com/problems/robot-bounded-in-circle/</a></p>
  <p>The only difference is our input for the function is a List and we need to return &quot;YES&quot; or &quot;NO&quot; for reach command based on if we go in a circle or not.</p>
  <p>My current does not pass all the test cases. I have provided the code and one of the test cases it does not pass:</p>
  <pre><code>public statis List&lt;String&gt; doesCircleExist(List&lt;String&gt; commands) {
  
      List&lt;String&gt; results = new ArrayList&lt;&gt;();
  
      for (String command : commands) {
        int currX = 0;
        int currY = 0;
        int currDir = 0;
        // north east south west
        int[][] dir = { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } };
        for (char c : command.toCharArray()) {
          switch (c) {
          case 'G':
            currX += dir[currDir][0];
            currY += dir[currDir][1];
            break;
          case 'R':
            currDir = (currDir + 1) % 4;
            break;
          case 'L':
            currDir -= 1;
            if (currDir &lt; 0)
              currDir = 3;
            break;
          }
        }
        if (currX == 0 &amp;&amp; currY == 0) {
          results.add(&quot;YES&quot;);
        } else {
          results.add(&quot;NO&quot;);
        }
      }
      return results;
    }
  }
  
  
  </code></pre>
  <pre><code>Input std(in)
  3
  6
  L
  RGRG
  
  Your output
  NO
  YES
  NO
  
  Expected output
  NO
  YES
  YES
  
  </code></pre>