title: Generating Strings By Rotating Elements
body: <p>I am trying to develop an algorithm which takes in an input string <code>S</code> and generate Strings by eliminating two characters at a time. Here's my code so far.</p>
  
  <pre><code>    String[] strings = {"a", "b", "c", "d", "e", "f"};
      int charsToBeRemoved = strings.length - 2;
  
      for( int i = 0; i &lt; strings.length; i++ )
      {
          int counter = 1;
          StringJoiner p = new StringJoiner( "|" );
          p.add( strings[i] );
          for( int j = i + 1; j &lt; strings.length; j++ )
          {
              p.add( strings[j] );
              counter += 1;
              if( counter == charsToBeRemoved )
              {
                  counter = 1;
                  j = ( charsToBeRemoved - 2 ) &gt; 0 ? j - ( charsToBeRemoved - 2 ) : j;
                  regexList.add( p.toString() );
                  p = new StringJoiner( "|" );
                  p.add( strings[i] );
              }
          }
      }
  </code></pre>
  
  <p>This provides the output : <code>[a|b|c|d, a|c|d|e, a|d|e|f, b|c|d|e, b|d|e|f, c|d|e|f]</code> . However, what I am trying to get is a rotating array based solution. Something like <code>[a|b|c|d, a|c|d|e, a|d|e|f, b|c|d|e, b|d|e|f, b|e|f|a, c|d|e|f, c|e|f|a, c|f|a|b], d|e|f|a, d|f|a|b, d|a|b|c</code>. In my current code, these outputs <code>b|e|f|a, c|e|f|a, c|f|a|b, d|e|f|a, d|f|a|b, d|a|b|c</code>are not formed because I need a way to access the previous elements of the array.</p>
  
  <p>Can anyone suggest a way to do so, or how I should change my approach?</p>