# Having fun with Palindrome words This article is not as interesting and reusable as other, but I think it might still be a nice example of how you we can speed up your code reducing the amount of branches. The `if` statement is very fast and usually we should not worry about its runtime cost, but there could be few cases in which avoiding it can provide a visible improvement. ## Coding interviews... At the time of writing this article, I find myself in the wonderful world of job searching. As a consequence, you probably know what that implies: coding interviews! I am fine with them, but the other day a person interviewing me asked the following question: > Can you write a function to find if a string is a [palindrome](https://en.wikipedia.org/wiki/Palindrome)? And I was thinking... ![fizzbuss](img/fizzbuzz.jpg) To be fair, I am sure he his a great guy and he was just breaking the ice. He certainly had the best intentions, but I think it could have been more productive for both of us to look at some real-world code I wrote in production instead! Nevertheless, this is the answer: ```C++ bool IsPalindrome(const std::string& str) { const size_t N = str.size(); const size_t N_half = N / 2; for(size_t i=0; i inline bool IsPalindromeWord(const std::string& str) { const size_t N = str.size(); const size_t N_half = (N/2); const size_t S = sizeof(uint32_t); // number of words of size S in N_half const size_t N_words = (N_half / S); // example: if N = 18, half string is 9 bytes and // we need to compare 2 pairs of words and 1 pair of chars size_t index = 0; for(size_t i=0; i