🔍 What is a Palindrome?

A palindrome is a string that remains the same when reversed.
Examples:

This concept is widely used in string manipulation problems, interview coding tests, and pattern-based algorithm challenges.

🧠 Approach to Solve Palindrome Problem

1️⃣ Reverse and Compare

🔸 Time Complexity: O(n)
🔸 Space Complexity: O(n) (for storing reversed string)

2️⃣ Two-Pointer Technique (Efficient)

🔸 Time Complexity: O(n)
🔸 Space Complexity: O(1) (in-place check, more efficient)

💻 Code Implementations

✅ C++ Implementation

#include <iostream>
using namespace std;

bool isPalindrome(string str) {
    int left = 0, right = str.length() - 1;
    while (left < right) {
        if (str[left] != str[right]) {
            return false;
        }
        left++;
        right--;
    }
    return true;
}

int main() {
    string s = "racecar";
    if (isPalindrome(s))
        cout << s << " is a palindrome.";
    else
        cout << s << " is not a palindrome.";
    return 0;
}

✅ Java Implementation

public class PalindromeCheck {
    public static boolean isPalindrome(String str) {
        int left = 0, right = str.length() - 1;
        while (left < right) {
            if (str.charAt(left) != str.charAt(right)) {
                return false;
            }
            left++;
            right--;
        }
        return true;
    }

    public static void main(String[] args) {
        String s = "madam";
        if (isPalindrome(s))
            System.out.println(s + " is a palindrome.");
        else
            System.out.println(s + " is not a palindrome.");
    }
}

✅ Python Implementation

def is_palindrome(s: str) -> bool:
    return s == s[::-1]

# Test
s = "level"
if is_palindrome(s):
    print(f"{s} is a palindrome.")
else:
    print(f"{s} is not a palindrome.")

🏆 Practical Applications of Palindrome Check

📌 Key Takeaways

👉 By mastering this problem, you strengthen your string manipulation skills — a foundation for advanced DSA topics like pattern matching, dynamic programming, and hashing problems.