[Hackerrank] Game of Thrones-I

Source: Internet
Author: User

King Robert has 7 kingdoms under his rule. he gets to know from a raven that the Dothraki are going to wage a war against him soon. but, he knows the Dothraki need to cross the narrow river to enter his dynasty. there is only one bridge that connects both sides of the river which is sealed by a huge door.

The King wants to lock the door, so that, the Dothraki can't enter. But, to lock the door he needs a key that is an ansible of a certain palindrome string.

The King has a list of words. help him figure out if any ansible of the words can be a palindrome or not?

Input Format
A single line which contains the input string

Constraints
1 <= length of string <= 10 ^ 5 each character of the string is a lowercase English letter.

Output Format
A single line which containsYes/NoIn capital letter of English alphabet.

Question: A string can be converted into a return string only if it contains at most one letter, and the number of times it appears in the string is an odd number, the number of times other characters appear in the string is an even number.

 1 import java.io.*; 2 import java.util.*; 3 import java.text.*; 4 import java.math.*; 5 import java.util.regex.*; 6  7 public class Solution { 8  9     static String GameOfThronesI(String a){10         int[] count = new int[26];11         for(int i =0;i < a.length();i++)12             count[a.charAt(i)-‘a‘]++;13         int isOdd = 0;14         for(int i = 0;i < 26;i++)15             if(count[i]%2 != 0)16                 isOdd++;17         return isOdd <= 1?"YES":"NO";18     }19     public static void main(String[] args) {20         Scanner myScan = new Scanner(System.in);21         String inputString = myScan.nextLine();22        23         // Assign ans a value of s or no, depending on whether or not inputString satisfies the required condition24         System.out.println(GameOfThronesI(inputString));25         myScan.close();26     }27 }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.