Check Plindrome String
C++
Medium
5 views
Problem Description
Q6: Check Palindrome String
Problem: Check if string reads same forwards and backwards.
Real Life: Words like "madam", "radar", "level".
Step-by-Step Logic:
1. Compare first and last characters
2. Move inward
3. If any pair doesn't match, not palindrome
4. If all match, it's palindrome
Official Solution
void string_q6_palindrome() {
string text = "radar";
bool isPalindrome = true;
int start = 0;
int end = text.length() - 1;
while(start < end) {
if(text[start] != text[end]) {
isPalindrome = false;
break;
}
start++;
end--;
}
cout << "String: " << text << endl;
if(isPalindrome) {
cout << "It is a PALINDROME" << endl;
} else {
cout << "It is NOT a palindrome" << endl;
}
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!