Intern — Middle
Searching for an element in a sorted array using a binary algorithm
livecode
Task condition
Given a sorted array of integers. It is required to write a binary search function that searches for a specified value and returns its position in the array. If the value is absent, the function should return -1.
sorted := []int{1, 4, 7, 19, 22, 34, 38, 55}
value := 19
// Expected result: index 3
func binarySearch(sorted []int, value int) int {
// implement
}