Permutation with repetition in Java (Strings are of the form: 00001112222)
<p>I have strings of the form <code>000011122222</code>. That is, consecutive digits repeated random no. of times. Some other examples could be:</p>

<pre><code>0011122223333
01222    
00011234444
001122222
</code></pre>

<p>and so on. I know, say for a string <code>01222</code>, that a total of <code>5!/3!</code> permutations are possible. I need to generate all these permutations for each such string. </p>

<p>I have tried generating permutations by various methods. One is by generating all the possible permutations (just as for strings without repetition), but since the strings that I would be using can be very large this can waste time generating too many redundant permutations.</p>

<p>Secondly, I have tried placing the digits at random indices of a character array equal to the size of the string and terminating the loop when the count of digits is same as in the input string. However, this way I am wasting a lot of memory and also taking up a lot of time.</p>

<p>I need an efficient way to generate permutations for such strings. Just an algorithm or code, either is welcome. I am using Java.</p>

<p>Thanks!</p>
