-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringMaker.java
More file actions
31 lines (27 loc) · 805 Bytes
/
StringMaker.java
File metadata and controls
31 lines (27 loc) · 805 Bytes
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
public class StringMaker {
public static void main(String[] args) {
System.out.println(isPossible("xy", "wz", "wxzy", "",-1));
}
static int isPossible(String a, String b, String c, String ans, int index)
{
if(index<c.length() && index>=0 && index<ans.length() && c.charAt(index)!=ans.charAt(index))
{
return 0;
}
if(c.equals(ans))
{
System.out.println(ans);
return 1;
}
int count = 0;
for(int i=0;i<a.length();i++)
{
count+= isPossible(a.substring(i),b,c,ans+a.charAt(i), index+1);
}
for(int i=0;i<b.length();i++)
{
count+= isPossible(a,b.substring(i),c,ans+b.charAt(i), index+1);
}
return count;
}
}