The Solution for hackerrank problem, Game of Thrones - I using C Program.
Passed Test cases: 20 out of 20
SOURCE CODE:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
void findPalind(char *arr)
{
char array[26]={0};
int flag = 0,i,j,k;
for(i=0;arr[i]!='\0';i++){
array[(arr[i]-97)]++;
}
for(i=0;i<26;i++){
if(array[i]%2!=0){
flag++;
}
}
if (flag <= 1)
printf("YES\n");
else
printf("NO\n");
}
int main() {
char arr[100001];
scanf("%s",arr);
findPalind(arr);
return 0;
}
its giving NO for aaabbb
ReplyDeletefor the testcase aaabbb there will be no anagram of the string which is palindrome.
Deletehence the answer is NO.
hey............why do we need to use..............char*arr in function argument and not just char arr.?
ReplyDeletein the main function arr is declared as an character array.
Deletechar arr - can store only a single character
so we need an pointer to get the base address of the array and use the pointer like an array.