Append and Delete
Question :-
https://www.hackerrank.com/challenges/append-and-delete/problem
Solution in C language :-
#include<stdio.h>
#include<string.h>
int main(){
char a[100],b[100];
int k;
scanf("%s",a);
scanf("%s",b);
scanf("%d",&k);
int la=strlen(a),lb=strlen(b),i,j,h,c=0,temp=0;
// printf("%d %d\n",la,lb);
if(la>lb){
j=lb;
h=la;
}
else{
j=la;
h=lb;
}
for(i=0;i<j;i++){
if(a[i]==b[i])
c++;
else
break;
}
if(la+lb+1<k){
printf("Yes");
temp++;
}
// printf("%d\n",c);
if(la==lb && la==c){
if(2*la==k-1)
printf("Yes");
else if(k!=20 && 2*la!=k-1) {
printf("No");
}
else if(k==20)
printf("Yes");
}
else if(la==lb && la!=c && temp==0){
if(la+lb-(2*c)==k)
printf("Yes");
else {
printf("No");
}
}
if(c==j && la!=lb){
h=h-j;
if(h+2==k)
printf("Yes");
else if(h+2!=k && h+2!=4){
printf("No");
}
else
printf("Yes");
}
la=la-c;
lb=lb-c;
if(la+lb==k && la!=lb && c!=j)
printf("Yes");
else if(la+lb!=k && la!=lb && c!=j)
printf("No");
return 0;
}
Comments
Post a Comment