This blog post is a part of a series on programming interview questions. In this blog post, I will show you how to find the min and max integer in Go Arrays or Slices. You can find more interview questions blog post here.

Sometimes an interviewer will ask you to find the min integer value in an array or to find the max integer value. The easiest to solve these two problems would be to sort the Array. This way you could return the **zero index** for the array of the **Min Value** and the **last index** for the **Max Value**. But the interviewer more and likely will not allow you to sort the array.

## Find The Min integer Value In an Array

To find the **Min integer** value we will create a variable to track the min value.Â We do this by setting the **Min** variable to math.MaxInt64.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
func Min(numbers []int) int { // Setup min to MaxInt64. min := math.MaxInt64 // Loop through all integers in array. for _, number := range numbers { // check if number is less than min. if number < min { // Set min to number min = number } } return min } |

You can run this code on the Go Playground here.

## Find The Max integer Value In an Array

To find the** Max integer** value we will create a variable to track the max value. We do this by setting the **Max** variable to math.MinInt64.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
func Max(numbers []int) int { // Set the max to MinInt64 max := math.MinInt64 // Loop through all integers in array. for _, number := range numbers { // Check if number is great than max. if number > max { max = number } } return max } |

You can run this code on the Go Playground here.

## Conclusion

In this blog post, you learn how to find the **Min integer** value in an Array and how to find the **Max integer** value in an Array.

### Resources

**Code Samples:Â **https://github.com/harrisonbrock/find-max-and-min-in-array-go