Palindrome Check

Asked atAdobe
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below

The problem

You are given a string s. Return true if the string is palindrome, otherwise false.

A string is called palindrome if it reads the same forward and backward.

Input : s = "hannah" Output : true Explanation : The given string when read backward is -> "hannah", which is same as when read forward. Hence answer is true.

Input : s = "aabbaaa" Output : false Explanation : The given string when read backward is -> "aaabbaa", which is not same as when read forward. Hence answer is false.

Input : s = "aabbccbbaa"

  • 1 <= s.length <= 105
  • s consist of only uppercase and lowercase English characters.

cpp

class Solution{	
	public:		
		bool palindromeCheck(string& s){
			//your code goes here
		}
};

java

class Solution {   
    public boolean palindromeCheck(String s) {
        //your code goes here
    }
}

python

class Solution:    
    def palindromeCheck(self, s):
        #your code goes here

javascript

class Solution {
    palindromeCheck(s) {
        //your code goes here
    }
}

csharp

class Solution {
    public bool palindromeCheck(string s) {
        //your code goes here
    }
}

go

func palindromeCheck(s string) bool {
	//your code goes here
}
Stuck? Show a way to structure it+
  1. 01Set pointers at both ends of the string.
  2. 02Compare the characters at each pair.
  3. 03Return false on the first mismatch.
  4. 04Move inward and return true when pointers cross.

Reference answer

Then expect these follow-ups

  • How would you ignore punctuation and case?

    Tests: input normalization

  • How would you find the longest palindromic substring?

    Tests: string algorithms

Free to read · better with Enzo

Practice this out loud with Enzo

Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.

Next question