Easy csharp

Check palindrome string

Problem

Check if "madam" is a palindrome.

Hints
  • Compare characters from start and end moving inward.

Your practice code

Ready — edit the code above and click Run.

Solution

using System;

class Program
{
    static void Main()
    {
        string s = "madam";
        int l = 0, r = s.Length - 1;
        bool ok = true;
        while (l < r)
        {
            if (s[l++] != s[r--]) { ok = false; break; }
        }
        Console.WriteLine(ok ? "Palindrome" : "Not Palindrome");
    }
}

Try solving on your own first, then reveal the official answer.

Explanation

Two-pointer compare from both ends—O(n) time, O(1) extra space.

Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details