-3
using System;
  using System.Collections.Generic;
    using System.Linq;
  using System.Text;
 using System.Threading.Tasks;

    namespace PelindromeIdentifier
  {
  class Program
  {
    static void Main()
    {
        int nNumberOfTestCases = 0;
        int.TryParse(Console.ReadLine(), out nNumberOfTestCases);

        String[] strTestCases = new String[nNumberOfTestCases];
        char[] arrChar;
        int nCharCount = 0;
        bool bAllow = false;
        int nCharIndex = 0;

        for (int nTestCase = 0; nTestCase < nNumberOfTestCases; nTestCase++)
        {
            strTestCases[nTestCase] = Console.ReadLine();
        }

        for (int nTestCase = 0; nTestCase < nNumberOfTestCases; nTestCase++)
        {
            bAllow = false;

            arrChar = strTestCases[nTestCase].Distinct().ToArray();

            for (nCharIndex = 0; nCharIndex < arrChar.Length; nCharIndex++)
            {
          nCharCount = strTestCases[nTestCase].Count(i =>                                     i.Equals(arrChar[nCharIndex]));

                if (strTestCases[nTestCase].Length % 2 == 0)
                {
                    if (nCharCount % 2 != 0)
                    {
                        Console.WriteLine("NO");
                        break;
                    }
                }
                else
                {
                    if (nCharCount % 2 != 0)
                    {
                        if (bAllow == true)
                        {
                            Console.WriteLine("NO");
                            break;
                        }
                        bAllow = true;
                    }
                }
            }

            if (nCharIndex == arrChar.Length)
            {`
                Console.WriteLine("YES");
            }
            }
            }
           }
              }

I tried this but there are some hidden test cases which are not working.Can anybody help me?In this program the program will ask user how many times you want to take input string and for every string it will return whether the string is palindrome or not

1 Answers1

0

Not sure to understand what you mean by possible test cases: I've changed your code and tested with 3 strings :

"coucou" : not palindrome

"kayak" : palindrome

"abcdeffedcba" : palindrome

and it works fine now:

palindrome

 static void Main()
    {
        int nNumberOfTestCases = 0;
        var input = 
        int.TryParse(Console.ReadLine(), out nNumberOfTestCases);

        String[] strTestCases = new String[nNumberOfTestCases];

        for (int nTestCase = 0; nTestCase < nNumberOfTestCases; nTestCase++)
        {
            strTestCases[nTestCase] = Console.ReadLine();
        }

        for (int nTestCase = 0; nTestCase < nNumberOfTestCases; nTestCase++)
        {

            if (strTestCases[nTestCase].SequenceEqual(strTestCases[nTestCase].Reverse()))
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");


        }
        Console.ReadKey();
    }
Xavave
  • 645
  • 11
  • 15
  • what would happen if we take empty string as a input? – Ruchit Raj Mar 04 '17 at 11:21
  • if we take empty string as input it will return YES, but if you prefer it to return no in this special case , you can modify this line : if (!string.IsNullOrEmpty(strTestCases[nTestCase]) && strTestCases[nTestCase].SequenceEqual(strTestCases[nTestCase].Reverse())) – Xavave Mar 04 '17 at 15:48