Cover image for Google
Logo
See All Photos
Best Places to Work 2020

Google

Engaged Employer

Google

Add an Interview

Interview Question

Software Engineer (Site Reliability) Interview

-

Google

Given a string, return true if after jumbling/rearranging the characters of the string will it be a palindrome. and false if not. eg: given string "evlel", it can be rearranged to "level" and thus it is a palindrome, and return true. eg: 1234 cannot be rearranged to become a palindrome hence false.

Interview Answers

4 Answers

1

A palindrome is a word that has the same spelling forward and backwards. “1234” are numbers and cannot be a palindrome.

Anonymous on

0

“acrecar” is a palindrome by that definition of the word, “racecar”, “dad”, “pop”, “poop”. These I feel like may be better examples. “454” would be an example of a palindrome that is a number.

Anonymous on

1

Count the occurrence of each character; if more than one char has odd number of occurrences, it’s false

Anonymous on

0

This solution uses an unordered map to be O(n) #include #include #include int main() { std::unordered_map map; const std::string test = "aabbbaaccc"; for(size_t i = 0; i ::const_iterator it = map.begin(); it != map.end(); ++it) { if (it->second % 2 != 0) { oddNumber++; if (oddNumber > 1) { std::cout << "Not palindrome" << std::endl; return -1; } } } std::cout << "Palindrome" << std::endl; return 0; }

Lorenzo on

Add Answers or Comments

To comment on this, Sign In or Sign Up.

Google Careers

Cover image for Google

​​We strive to provide Googlers and their loved ones with a world-class benefits experience, focused on supporting their physical,...More

  • Where we work
  • Building belonging
  • Googler stories
  • Build your future
This is the employer's chance to tell you why you should work for them. The information provided is from their perspective.