QM13B - editorial

PROBLEM LINK:

Practice

Contest

Author: Chandan Boruah

Tester: Chandan Boruah

Editorialist: Chandan Boruah

DIFFICULTY:

SIMPLE

PREREQUISITES:

Linked List (for author’s solution)

PROBLEM:

Given a word find if you can rearrange the words to form a palindrome.

QUICK EXPLANATION:

Add to linked list and remove from linked as you get same letter in the word, alternatively. In the end if only 1 or 0 letters are left, then it can be a palindrome.

EXPLANATION:

Everytime a letter appears twice it can be eliminated since it can be rearranged into the palindrome. So add to linked list if a new letter is found if its found again remove both. If in the end 1 or 0 letters are left then it can be a palindrome.

AUTHOR’S C# SOLUTIONS:

using System;
using System.Collections.Generic;
class some
{
	public static void Main()
	{
		string s=Console.ReadLine();
		List<char>cc=new List<char>();
		for(int i=0;i<s.Length;i++)
		{
			if(cc.Contains(s[i]))
			{
				cc.Remove(s[i]);
			}
			else
			{
				cc.Add(s[i]);
			}
		}
		if(cc.Count<=1)Console.WriteLine(1);
		else Console.WriteLine(0);			
	}
}
//