Game of Thrones - I

Problem Statement :

Dothraki are planning an attack to usurp King Robert's throne. King Robert learns of this conspiracy from Raven and plans to lock the single door through which the enemy can enter his kingdom.

But, to lock the door he needs a key that is an anagram of a palindrome. He starts to go through his box of strings, checking to see if they can be rearranged into a palindrome. Given a string, determine if it can be rearranged into a palindrome. Return the string YES or NO.


s = 'aabbccdd'

One way this can be arranged into a palindrome is aabbccdd. Return YES.

Function Description

Complete the gameOfThrones function below.

gameOfThrones has the following parameter(s):

string s: a string to analyze


string: either YES or NO

Input Format

A single line which contains s.


1  <=   |s|   <=  10^5
s contains only lowercase letters in the range ascii[a . . . z ]

Solution :


                            Solution in C :

In  C++  :

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

int main() {
    int a[26]={0};
    string s;
    int l=s.length();
    for(int i=0;i<l;i++)
    int c=0;
    for(int i=0;i<26;i++)
    return 0;

In  Java  :

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

public class Solution {
    static String s;
    static int hash[];
    public static void main(String[] args) {
       hash=new int[26];
       Scanner sc = new Scanner(;;
       int i;
           int temp;
       int odd=0; 
       int set=0;
                else odd=1;
       else if(set==1)

In  C :


int main()
	int a[26],i,tp;
	char c;
	for (i=0;i<26;i++)
	while ((c=getchar())!=EOF&&c!='\n')
	for (i=0;i<26;i++)
		if (a[i]%2!=0&&tp==1)
		else if (a[i]%2!=0&&tp==0)
	if (i==26)
	return 0;

In   Python3  :

string = input()
character_count = {}
for i in string:
    if i not in character_count:
        character_count[i] = string.count(i)
odd_counts = 0
for i in character_count:
    if character_count[i] % 2 == 1:
        odd_counts += 1
if odd_counts > 1:

View More Similar Problems

Get Node Value

This challenge is part of a tutorial track by MyCodeSchool Given a pointer to the head of a linked list and a specific position, determine the data value at that position. Count backwards from the tail node. The tail is at postion 0, its parent is at 1 and so on. Example head refers to 3 -> 2 -> 1 -> 0 -> NULL positionFromTail = 2 Each of the data values matches its distance from the t

View Solution →

Delete duplicate-value nodes from a sorted linked list

This challenge is part of a tutorial track by MyCodeSchool You are given the pointer to the head node of a sorted linked list, where the data in the nodes is in ascending order. Delete nodes and return a sorted list with each distinct value in the original list. The given head pointer may be null indicating that the list is empty. Example head refers to the first node in the list 1 -> 2 -

View Solution →

Cycle Detection

A linked list is said to contain a cycle if any node is visited more than once while traversing the list. Given a pointer to the head of a linked list, determine if it contains a cycle. If it does, return 1. Otherwise, return 0. Example head refers 1 -> 2 -> 3 -> NUL The numbers shown are the node numbers, not their data values. There is no cycle in this list so return 0. head refer

View Solution →

Find Merge Point of Two Lists

This challenge is part of a tutorial track by MyCodeSchool Given pointers to the head nodes of 2 linked lists that merge together at some point, find the node where the two lists merge. The merge point is where both lists point to the same node, i.e. they reference the same memory location. It is guaranteed that the two head nodes will be different, and neither will be NULL. If the lists share

View Solution →

Inserting a Node Into a Sorted Doubly Linked List

Given a reference to the head of a doubly-linked list and an integer ,data , create a new DoublyLinkedListNode object having data value data and insert it at the proper location to maintain the sort. Example head refers to the list 1 <-> 2 <-> 4 - > NULL. data = 3 Return a reference to the new list: 1 <-> 2 <-> 4 - > NULL , Function Description Complete the sortedInsert function

View Solution →

Reverse a doubly linked list

This challenge is part of a tutorial track by MyCodeSchool Given the pointer to the head node of a doubly linked list, reverse the order of the nodes in place. That is, change the next and prev pointers of the nodes so that the direction of the list is reversed. Return a reference to the head node of the reversed list. Note: The head node might be NULL to indicate that the list is empty.

View Solution →