Facebook
4.6 of 5 636 reviews
www.facebook.com Menlo Park, CA 5000+ Employees

Facebook Software Engineer Interview Question (student candidate)

"Check if two strings are Palindrome"
Add Tags [?]
Answer Flag Question

Part of a Software Engineer Interview Review - one of 1,001 Facebook Interview Reviews

Answers & Comments

0
of 0
votes
non-recursive:
bool pali(string a, string b){
 if(a.size() != b.size())
     return false;

 for (int i = 0; i<a.size();i++){
     if(a.charAt(i) != b.charAt(a.size() - i){
         return false;
    }
}
return true;
}

recursive

bool is_pali(string a, string b){
      if (a.size() != b.size() or a.size() == 0 or a.charAt(0) != b.charAt(b.size()-1)){
          return false;
     }
      is_pali(a.substring(1),b.substring(0,b.size - 1);
}
- Adi on Feb 12, 2013 Flag Response
0
of 0
votes
int palindrome(string a)
{
  assert(a.length());//Abort is string empty

  int val = 1;//default value is true
  for(int i = 0; i < a.length(); i++)//Can actually restrict i:0-length/2
        val *= (a[i]==a[a.length()-1-i]);
  return val;
}
- S on Feb 17, 2013 Flag Response
0
of 0
votes
Python implimentation

string==string[::-1]

Of course your interviewer will ask you to elaborate.
- Dan on Aug 3, 2013 Flag Response

To comment on this question, Sign In with Facebook or Sign Up


Tags are like keywords that help categorize interview questions that have something in common.

Glassdoor is your free inside look at Facebook interview questions and advice. All interview reviews posted anonymously by Facebook employees and interview candidates.