forked from HarshCasper/NeoAlgo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_for_subsequence.c
More file actions
43 lines (38 loc) · 864 Bytes
/
check_for_subsequence.c
File metadata and controls
43 lines (38 loc) · 864 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
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
#include <string.h>
int main()
{
char str1[1000] , str2[1000];
int i = 0 , j = 0; // i will point to string 1 and j will point to string 2
printf(" Enter first string :\n");
scanf("%s" , str1); // str1 is substring
printf(" Enter second string :\n");
scanf("%s" , str2); //str2 is full string
while (i < strlen(str1) && j < strlen(str2))
{
if (str1[i] == str2[j])
{
i++;
}
j++;
}
if (i == strlen(str1))
{
printf("Yes, str1 is substring of str2\n");
}
else
{
printf("No, str1 is not a substring of str2\n");
}
return 0;
}
/*
Time Complexity: O(n)
Space Complexity: O(1)
Input:
DTH SDFDTHFGB
QBR EQVBA
Output:
Yes, str1 is substring of str2
No, str1 is not substring of str2
*/