Validate Palindrome (Easy)

Good evening! Here's our prompt for today.

You may see this problem at Microsoft, Amazon, Linkedin, Stripe, Paypal, Yelp, Airbnb, Reddit, Datadog, Rubrik, Gusto, Lucid Software, Digitalocean, Servicenow, Zoom, Intel, and Zoominfo.

Given a string str, can you write a method that will return True if is a palindrome and False if it is not? If you'll recall, a palindrome is defined as "a word, phrase, or sequence that reads the same backward as forward". For now, assume that we will not have input strings that contain special characters or spaces, so the following examples hold:

1let str = 'thisisnotapalindrome';
2isPalindrome(str);
3// false
4
5str = 'racecar';
6isPalindrome(str);
7// true

For an extra challenge, try to ignore non-alphanumerical characters. The final solution that we present will handle all edge cases.

Constraints

  • Length of the given string <= 100000
  • The string will consist of ASCII characters (some or all)
  • Expected time complexity : O(n)
  • Expected space complexity : O(1)
JAVASCRIPT
OUTPUT
Results will appear here.