May 16, 2020

Go Interview Question #2 - Write a function to check if a string is a palindrome

This question is very common on interviews, and while fairly straightforward, plenty developers mess it up on the interview.

What is a palindrome? Webster dictionary defines it as a word, sentence or number that reads the same forwards and backwards. Some examples are: dad, 1881, abba.

There are a few approaches to solving this problem, we can reverse the array of characters and compare the resulting string for example. The more efficient way of doing this is to compare the characters from the beginning and from the end one-by-one. This way we can quit comparison as soon as we find a non-matching character.

Let’s convert this to Go code :)


© Ilya Nemtsev 2019

Powered by Hugo.