Check permutation | solution of cracking the coding interview

  Problem:- 

   Give two strings , write a method to decide if one is permutation of other.

 Code:-

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int f1[122],f2[122];
int main()
{
char s1[50],s2[50];
printf(“Enter the first stringn”);
scanf(“%[^n]”,s1);
// counting of frequency of the characters of first string
for(int i=0;s1[i];i++)
{
int a=s1[i];
f1[a]++;
}
fflush(stdin);
printf(“Enter the second stringn”);
scanf(“%s”,s2);
// counting of frequency of the characters of first string
for(int i=0;s2[i];i++)
{
int a=s2[i];
f2[a]++;
}
// checking of permutation
int i;
for(i=0;i<=122;i++)
{
if(f1[i]!=f2[i])
{
printf(“Strings are not permutation of each othern”);
break;
}
}
if(i==123)
printf(“permutation string”);
}

Output:-

Enter the first string
easycodingzone
Enter the second string
easyzonexdry
Strings are not permutation of each other

Recommended Post:

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

Key points:-

 MCQs:-

Leave a Reply

Your email address will not be published.