-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpermutationInString.cpp
More file actions
40 lines (40 loc) · 922 Bytes
/
permutationInString.cpp
File metadata and controls
40 lines (40 loc) · 922 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
#include<iostream>
#include<string>
using namespace std;
bool isFreqSame(int freq1[],int freq2[]){
for (int i=0 ; i<26 ; i++){
if(freq1[i]!=freq2[i]){
return false;
}
}
return true;
}
int main(){
bool found=false;
string s1="muskan agarwal";
string s2="gaa";
int freq[26]={0};
for (int i=0 ; i<s2.length() ; i++){
int idx=s2[i]-'a';
freq[idx]++;
}
int winSize=s2.length();
for (int i=0 ; i<s1.length() ; i++){
int winFreq[26]={0};
int winIdx=0, idx=i;
while(winIdx<winSize && idx<s1.length()){
winFreq[s1[idx]-'a']++;
winIdx++, idx++;
}
if (isFreqSame(freq,winFreq)){
found=true;
break;
}
}
if (found==true){
cout<<"Found";
}else{
cout<<"Not found";
}
return 0;
}