# Basic Interview Questions on Go Programming

package main

import (
“fmt”
“strconv”
)

func main() {
n := 3
for i := 1; i <= n; i++ {
fmt.Printf(strconv.Itoa(i))
}
}

Output: 123

2. Given a year, determine whether it is a leap year.

package main
import “fmt”

func main() {
fmt.Println(“Enter a year:”)
var year int
fmt.Scanln(&year)
if year%4 == 0 && year%100 == 0 || year%400 == 0 {
fmt.Println(“It’s a leap year.”)
} else {
fmt.Println(“Not a leap year!!”)
}
}

3. Print a list of all possible coordinates i, j, k given by on a 3D grid where the sum of is i+j+k not equal to n .

package main

import “fmt”

func main() {
n := 2
for i := 0; i < n; i++ {
for j := 0; j < n; j++ {
for k := 0; k < n; k++ {
if i+j+k != n {
slice := []int{i, j, k}
fmt.Println(slice)
}
}
}
}

}

Output:

[0 0 0]
[0 0 1]
[0 1 0]
[1 0 0]
[1 1 1]

4. Given the participants’ score sheet for your University Sports Day, you are required to find the runner-up score.

package main

import (
“fmt”
“sort”
)

func main() {
score := []int{1, 5, 3, 4, 6}
sort.Ints(score)
runnerup_score := score[len(score)-2]
fmt.Println(runnerup_score)

}

Output: 5

5. Given the names and grades for each student in a class of N students, store them in a nested list and print the name(s) of any student(s) having the second lowest grade.

package main

import (
“fmt”
“sort”
)

func main() {
student := []struct {
Name string
Score int
}{
{“Alice”, 81},
{“Rashik”, 90},
{“Eve”, 72},
{“Bob”, 72},
}

sort.SliceStable(student, func(i, j int) bool {
return student[i].Score < student[j].Score
})
fmt.Println(student)
}

To be Continued…..

--

--