Palindrome check
Inputs
text is 0 to 16 lowercase letters (a to z).
Your tasks
- Use a loop over positions
0up to (but not including) half the length oftext. - At each position
i, comparetext[i]with the character the same distance from the other end:text[len - 1 - i]. If they differ, return false straight away. - If the loop finishes without a mismatch, the text reads the same both ways.
- Complete
isPalindromeso it returns true or false. Return it, do not print it.
Example
With text = "racecar", isPalindrome returns true.
Rules
- An empty text and a one-letter text are palindromes.
Test data
TEST DATA 1: text is "racecar"
TEST DATA 2: text is "abca"
Practice focus
Text is just a list of characters, so everything you know about lists applies. String problems in interviews are array problems with letters.