Grokking LinkedIn Coding Interview
Ask Author
Back to course home

0% completed

Vote For New Content
Ana Calin
Palindrom solution error- golang

Ana Calin

Jun 20, 2025

Here's my solution for the palindrome problem that compiles and runs successfully on my editor:

package main import ( "fmt" "regexp" "strings" ) type Solution struct { } func (sol *Solution) isPalindrome(s string) bool { first, last := 0, len(s)-1 for first < last { if s[first] != s[last] { return false } first++ last-- } return true } func normalise(s string) string { toLowerStr := strings.ToLower(s) reg := regexp.MustCompile(`[^a-z]`) transformedStr := reg.ReplaceAllString(toLowerStr, "") return transformedStr } func main() { str := "A man, a plan, a canal, Panama!" normalisedStr := normalise(str) solution := Solution{} fmt.Println("Is my string a palindrome?", solution.isPalindrome(normalisedStr)) }

However when running the code using the inbuilt editor I get the following error:

# go/pkg ./UserCode.go:2:1: syntax error: non-declaration statement outside function body note: module requires Go 1.13.5

Can you let me know why I'm seeing this?

0

0

Comments
Comments

On this page