0 votes
in GoLang by
Implement min and max behavior

1 Answer

0 votes
by

Implement Min(x, y int) and Max(x, y int) functions that take two integers and return the lesser or greater value, respectively.

Solution

By default, Go only supports min and max for floats using math.min and math.max. You’ll have to create your own implementations to make it work for integers.

package main

import "fmt"

// Min returns the smaller of x or y.

func Min(x, y int) int {

        if x > y {

                return y

        }

Related questions

0 votes
asked Aug 11, 2022 in GoLang by SakshiSharma
0 votes
asked Apr 27, 2023 in GoLang by Robin
...