package main import "fmt" func upper_bound_ (v int, a[] int) int{ len_a := len(a) left := 0 right := len_a - 1 for { mid := left + (right - left) / 2 if a[mid] == v { return mid }else if a[mid] > v{ right = mid - 1 }else if a[mid] < v{ left = mid + 1 } if left > right { break } } return -1 } func main() { a := [] int {1, 2, 3, 4, 5} fmt.Println(upper_bound_(6, a)) }