Golang coding Interview questions

IT doubts

Question 1 : Generate a Fibonacci series till nth number

Output: 0, 1, 1, 2, 3, 5, 8, 13, 21, ……n

n:=7
t1,t2, t3 := 0,1,0
            for i:=1; i<=n; i++ {
                     fmt.Print(t1)
                     t3 = t1+t2
                     t1,t2 = t2,t3

          }

Question 2: Reverse string  and check Palindrome

Input : 321

Output: 123

Solution: 

str:=”321″

result := “”

fmt.Print(len(str))

for _, value := range str{

result = string(value) + result 

}

Question 3:  Palindrome

Input : ABCDCBA

Output: yes

end := len(str) – 1;

 mid := len(str)/2;

for i:=0; i < mid; i++{

if string(str[i]) != string(str[end]){

fmt.Print(“Not Palindrome”)

break

        }

end = end -1

}

if(end == mid){

fmt.Print(“Palindrome”)

}

Leave a Reply

Your email address will not be published. Required fields are marked *