title: Return an array of strings containing all sub-sequences for s (except the empty string) ordered lexicographically?
body: <p>I need the code (or snippet of the code for the following problem or hint on how to solve):</p>
  
  <p>A sub sequence of string s is obtained by deleting one or more characters from s. The set of sub sequences for string <code>s = abc</code> would be <code>a, ab, ac, abc, b, bc, c,</code> and the empty string (which is a sub sequence of all strings).</p>
  
  <p>Find all possible sub sequences for s and print them in lexicographic order.</p>
  
  <p>This is what i have come out with but it's not working:</p>
  
  <pre><code>TreeSet&lt;String&gt; ls = new TreeSet&lt;&gt;();
  
      for(int i=0;i&lt;s.length();i++)
      {
  
          for(int j=i;j&lt;s.length();j++)
          {
              StringBuffer sb = new StringBuffer();
  
              for(int k=i;k&lt;j+1;k++)
              {
                  sb.append(s.charAt(k));
              }
  
              ls.add(sb.toString());
          }
  
      }
  
  
  
  
      return ls.toArray(new String[ls.size()]);
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>TestCase : abc
  </code></pre>
  
  <p>Output:
  a
  ab
  abc
  b
  bc
  c</p>
  
  <p>Expected Output:
  a
  ab
  abc
  ac
  b
  bc
  c</p>