Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So, I see you want to implement a method: <code>subSequence(s, n)</code>: Which returns a collection of all character character <em>combinations</em> from <code>s</code> of length <code>n</code>, such that ordering is preserved.</p> <p>In the spirit of your desire to <strong>not</strong> provide you with code, I assume you would prefer no pseudo-code either. So, I will explain my suggested approach in a narrative fashion, leaving the translation to procedural code as an exercise-to-the-reader(TM).</p> <p>Think of this problem where you are obtaining all combinations of character <em>positions</em>, which could be represented as an array of bits (a.k.a. flags). So where <code>s="abcd"</code> and <code>n=3</code> (as in your example), all combinations could be represented as follows:</p> <pre><code>1110 = abc 1101 = abd 1011 = acd 0111 = bcd </code></pre> <p>Note, that we start with a bit-field where all characters are turned "on" and then shift the "off" bit over by 1. Things get interesting in an example where <code>n &lt; length(s) - 1</code>. For example, say <code>s="abcd"</code> and <code>n=2</code>. Then we have:</p> <pre><code>1100 = ab 1001 = ad 1010 = ac 0110 = bc 0101 = bd 0011 = cd </code></pre> <p>The recursion comes into play when you analyze a sub set of the bit-fields. Hence, a recursive call would reduce the size of the bit-field and "bottom-out" where you have three flags:</p> <pre><code>100 010 001 </code></pre> <p>The bulk of the work is a recursive approach to find all of the bit-fields. Once you have them, the positions of each bit can be used as an index in the the array of characters (that is <code>s</code>).</p> <p>This should be sufficient to get you started on some pseudo-code!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload