Skip to content

Commit f7392aa

Browse files
committed
Added String Problem of Uncompressing and its Algo
Fixes matthewsamuel95#4
1 parent 665a38e commit f7392aa

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int T;
7+
cin>>T;
8+
while(T--)
9+
{
10+
string s,t;
11+
cin>>s;
12+
cin>>t;
13+
int flag = 0;
14+
int m = s.length();
15+
int n = t.length();
16+
if(t.length()<=s.length() || s[0]!=t[0])
17+
{
18+
cout<<"NO"<<endl;
19+
}
20+
else
21+
{
22+
int i=1,j=1;
23+
while(i<m && j<n)
24+
{
25+
if(s[i]==t[j])
26+
{
27+
i++;
28+
j++;
29+
}
30+
else if(s[i-1]==t[j])
31+
{
32+
j++;
33+
}
34+
else
35+
{
36+
flag = 1;
37+
break;
38+
}
39+
}
40+
if(flag==0)
41+
{
42+
while(j<n)
43+
{
44+
if(s[m-1]==t[j])
45+
j++;
46+
else
47+
{
48+
flag = 1;
49+
break;
50+
}
51+
}
52+
}
53+
if(flag==1)
54+
{
55+
cout<<"NO"<<endl;
56+
}
57+
else
58+
{
59+
cout<<"YES"<<endl;
60+
}
61+
}
62+
}
63+
return 0;
64+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Arya has 2 strings, s and t. She has been given a task to uncompress the string s and verify if string t can be constructed. While uncompressing the string s, she can repeat each letter in s any non-zero number of times, i.e for s="aab", possible uncompressed forms can be "aabbb", "aaabb" etc.
2+
3+
Determine if she is able to perform the task.
4+
5+
### Input:
6+
7+
The first line contains an integer T, the number of test cases.
8+
For each test case, the first line contains the string s and second line contains the string t.
9+
10+
Sample:
11+
```sh
12+
2
13+
aaa
14+
aa
15+
aa
16+
aaa
17+
```
18+
19+
### Constraints:
20+
21+
1<=T<= 50,
22+
1<=|s|<=200,
23+
1<=|t|<=1000,
24+
25+
### Output:
26+
27+
For each test case, print "Yes" if Arya is able to perform the task, else print "No" in a new line.
28+
29+
Sample
30+
```sh
31+
NO
32+
YES
33+
```

0 commit comments

Comments
 (0)