gvi-zw
Last Updated: November 07, 2016
·
51
· rogerthat

Subsequence of a Word


public class TestPad {
  public static void main(String[] args) {
    String a = "rahul";

    for (int i = 1; i <= a.length(); i++) {
      print("", a, i);
    }

  }

  public static void print(String prefix, String remaining, int size) {
    if (size == 0) {
      // We have found the desired length word
      System.out.println(prefix);
      return;
    }

    if(remaining.length() == 0) {
      return;
    }

    print(prefix + remaining.charAt(0), remaining.substring(1), size - 1);
    print(prefix, remaining.substring(1), size);
  }
}
Say Thanks
Respond