Check whether a string is a palindrome
Company: Citadel
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates string manipulation skills and basic algorithmic competency, specifically palindrome recognition and index-based character comparison, within the Coding & Algorithms domain.
Constraints
- 1 <= len(s) <= 2 * 10^5
- s contains only lowercase English letters
Examples
Input: 'racecar'
Expected Output: True
Explanation: The string reads the same from left to right and right to left.
Input: 'hello'
Expected Output: False
Explanation: The first and last characters differ, so it is not a palindrome.
Input: 'a'
Expected Output: True
Explanation: A single character is always a palindrome.
Input: 'abba'
Expected Output: True
Explanation: The mirrored pairs are ('a','a') and ('b','b'), so the string is a palindrome.
Input: 'abca'
Expected Output: False
Explanation: The middle mirrored pair is ('b','c'), which does not match.
Hints
- Compare characters from the beginning and the end of the string at the same time.
- If any mirrored pair of characters is different, you can return `False` immediately.