Tesla Interview Question

Reverse a string but ignore special characters

Interview Answer

Anonymous

Dec 14, 2018

package main import "fmt" func reverse(s string) string { buf := make([]byte, len(s)) j:=len(s)-1 for i:=0; i 'z' { buf[i] = s[i] i++ continue } if s[j] 'z' { j-- continue } buf[i] = s[j] j-- } return string(buf) } func main() { fmt.Println(reverse("hell,o world!")) }