title: After how many iterations the original string repeats?
body: <p>The task:</p>
  <p>Implement the a method at each iteration of which, the odd characters of the string are combined and wrapped to its beginning, and the even characters are wrapped to the end. When implementing the code, it should be noted that the input string can contain a very large number of characters, and the number of iterations can be huge. Optimize your code in terms of speed and resource consumption.</p>
  <p>Input and expected output examples:</p>
  <p>input string = &quot;123456789&quot;, iteration = 1, ExpectedResult = &quot;135792468&quot;</p>
  <p>input string = &quot;123456789&quot;, iteration = 2, ExpectedResult = &quot;159483726&quot;</p>
  <p>input string = &quot;123456789&quot;, iteration = 3, ExpectedResult = &quot;198765432&quot;</p>
  <p>input &quot;1234567890&quot;, iteration = int.MaxValue, ExpectedResult = &quot;1357924680&quot;</p>
  <p>I wrote the following code in C# which works fine with relatively small iterations but it is not efficient with large numbers (int.MaxValue for instance). I noticed that after certain number of iterations the given string returns to its initial state, for example string &quot;123456789&quot; repeats after 6 iterations. This means that on the 7th iteration the cycle run again which is unnecessary. I want to decrease the number of iterations so the code won't need to run extra times. How do I find the pattern? String repeats at different iterations depending on its length.</p>
  <pre><code>//source is the input string
  
          for(int j = 0; j &lt; iteration; j++){
              for(int i = 0; i &lt; source.Length; i+=2){
                  stack.Push(source[i]);
              }
  
              for(int i = 1; i &lt; source.Length; i+=2){
                  stack.Push(source[i]);
              }
  
              char[] res = new char[stack.Count];
  
              for(int i = res.Length - 1; i &gt;= 0; i--){
                  res[i] = stack.Pop();
              }
  
              source = string.Join(&quot;&quot;, res);
          }
  </code></pre>