Skip to content

Commit e0a3495

Browse files
authored
Update and rename Does s Contain t to Does s contain t
1 parent 3b9b714 commit e0a3495

File tree

2 files changed

+57
-24
lines changed

2 files changed

+57
-24
lines changed

Course 2 - Data Structures in JAVA/Test 1/Does s Contain t

-24
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
Given two string s and t, write a function to check if s contains all characters of t (in the same order as they are in string t). Return true or false. Do it recursively.
3+
E.g. : s = “abchjsgsuohhdhyrikkknddg” contains all characters of t=”coding” in the same order. So function will return true.
4+
5+
Input Format :
6+
Line 1 : String s
7+
Line 2 : String t
8+
9+
Output Format :
10+
true or false
11+
12+
Sample Input 1 :
13+
abchjsgsuohhdhyrikkknddg
14+
coding
15+
Sample Output 1 :
16+
true
17+
18+
Sample Input 2 :
19+
abcde
20+
aeb
21+
Sample Output 2 :
22+
false
23+
*/
24+
25+
public class Solution {
26+
public static boolean checkSequence(String a, String b) {
27+
/* Your class should be named Solution
28+
* Don't write main().
29+
* Don't read input, it is passed as function argument.
30+
* Return output and don't print it.
31+
* Taking input and printing output is handled automatically.
32+
*/
33+
34+
return checkSequence(a,b,0,0);
35+
}
36+
37+
public static boolean checkSequence(String a, String b, int a_idx, int b_idx)
38+
{
39+
if (b_idx==b.length())
40+
{
41+
return true;
42+
}
43+
if (a_idx==a.length())
44+
{
45+
return false;
46+
}
47+
if (b.charAt(b_idx)==a.charAt(a_idx))
48+
{
49+
return checkSequence(a,b,a_idx+1,b_idx+1);
50+
}
51+
else
52+
{
53+
return checkSequence(a,b,a_idx+1,b_idx);
54+
}
55+
56+
}
57+
}

0 commit comments

Comments
 (0)