Explorer
JavaScript

Compare characters from both ends moving inward. If all match, it is a palindrome.

Problem Statement

Given a string, check if it is a palindrome.

Examples

Input: str = "madam"

Output: True

Explanation: Combining the input according to Check if String is Palindrome logic yields True.

Input: str = "hello"

Output: False

Explanation: Combining the input according to Check if String is Palindrome logic yields False.

Complexity

Time Complexity: O(n)

Space Complexity: O(1)

Check if String is Palindrome

Easy
Given a string, check if it is a palindrome.
Example Scenarios
1Example 1
Input: str = "madam"
Output: True
Explanation:

Combining the input according to Check if String is Palindrome logic yields True.

2Example 2
Input: str = "hello"
Output: False
Explanation:

Combining the input according to Check if String is Palindrome logic yields False.

Editor
Loading Editor...
str =
"madam"
Output:Click "Run" above to execute and verify your code here.
True