Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

HackerRank Game of Thrones I problem solution

YASH PAL, 31 July 2024

In this HackerRank Game of Thrones – I problem solution we have given a string, determine if it can be rearranged into a palindrome. Return the string YES or NO.

HackerRank Game of Thrones I problem solution

Problem solution in Python.

def can_be_palindrome(string):
    string = sorted(string)
    current_letter_count = 1
    middle = False
    for index, char in enumerate(list(string[1:])):
        if string[index] != char:
            if current_letter_count % 2:
                if not middle:
                    middle = True
                else:
                    return False
        current_letter_count += 1
    return True

print('YES' if can_be_palindrome(input()) else 'NO')

{“mode”:”full”,”isActive”:false}

Problem solution in Java.

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    public static void main(String[] args) {
        Scanner myScan = new Scanner(System.in);
        String inputString = myScan.nextLine();
       
        String ans;
        int[]count=new int[26];
        for(int i=0;i<inputString.length();i++)
            count[inputString.charAt(i)-'a']++;
        int odds=0;
        for(int i=0;i<26;i++)
            if(count[i]%2==1)
                odds++;
        if(((inputString.length()%2==0)&&odds==0)||((inputString.length()%2==1)&&odds==1))
           ans="YES";
        else 
           ans="NO";
        
        System.out.println(ans);
        myScan.close();
    }
}

{“mode”:”full”,”isActive”:false}

Problem solution in C++.

#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;


int main() {
	vector<long long> stat(26,0);
	string str;
	getline(cin,str);
	for(int i=0; i<str.size(); i++){
		stat[str[i]-'a']++;
	}
	int odd=0;
	for(int i=0; i<stat.size(); i++){
		if(stat[i] % 2 == 1)
			odd++;
		if(odd > 1){ 
			cout<<"NO";
			break;
		}
	}
    if(!(odd >1 ))
        cout<<"YES";
	return 0;
}

{“mode”:”full”,”isActive”:false}

Problem solution in C.

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
   int x = 0, i, y = 0;
   char a[1000001], b[27]={0};
   scanf ("%s", &a);
   x = strlen (a);
    for (i = 0; i < x; i++){
        b[a[i]-'a']++;
    }
    for (i = 0; i < 26; i++){
        if (b[i]%2 == 1) y++;
    }
    if (x % 2 == 1){
        if (y == 1){
            printf ("YES");
            return 0;
        }
    }else{
        if (y == 0){
            printf ("YES");
            return 0;
        }
    }
   printf("NO");
   return 0;
}

{“mode”:”full”,”isActive”:false}

algorithm coding problems

Post navigation

Previous post
Next post
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
How to download udemy paid courses for free

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
©2025 Programming101 | WordPress Theme by SuperbThemes
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions