Check if a String is a Palindrome in Go

This blog post is a part of a series on programming interview questions. You can find more interview questions blog post here.

Question

You are given a string and are asked to write a method to return true if the string is a palindrome and to return false otherwise. A palindrome is a string that reads the same from front to back like radar.

Solutions

Case Matters

This solution will only work if the characters of the string are the same case. For example, radar is a palindrome but Radar is not because the first capitalize.

You can run this code on the Go Playground here.

Case Dose Not Matters

This solution will work no matter what case the characters are. For example, radar and Radar are both palindromes. This is because we use the function ToLower to change all the character in the string to lowercase.

You can run this code on the Go Playground here.

Conclusion

In this blog post, you learn two ways to check if the string is a palindrome or not using Go.

Harrison Brock