-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathProblem_11_1.java
More file actions
34 lines (28 loc) · 1.07 KB
/
Problem_11_1.java
File metadata and controls
34 lines (28 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package strings;
import java.util.*;
// Problem Title => Print all Subsequences of a string.
public class Problem_11_1 {
// Declare a global linkedList.list
static List<String> al = new ArrayList<>();
private static void findSubSequences(String s, String ans) {
if (s.length() == 0) {
al.add(ans);
return;
}
// We add add-ing 1st character in string
findSubSequences(s.substring(1), ans + s.charAt(0));
// Not adding first character of the string because the concept of subsequence
// either character will present or not.
findSubSequences(s.substring(1), ans);
}
// Creating a public static Arraylist such that we can store values
// IF there is any question of returning then we can directly return too
// public static ArrayList<String> al = new ArrayList<String>();
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
sc.close();
findSubSequences(s, "");
System.out.println(al);
}
}