Tuesday, 23 September 2014

Hackerrank Game of Thrones - I

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;  
 }  




4 comments:

  1. Replies
    1. for the testcase aaabbb there will be no anagram of the string which is palindrome.
      hence the answer is NO.

      Delete
  2. hey............why do we need to use..............char*arr in function argument and not just char arr.?

    ReplyDelete
    Replies
    1. in the main function arr is declared as an character array.

      char 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.

      Delete