Sobes.tech
Junior — Senior

Searching for a target element in a sorted array

livecode

Task condition

Implement a function that takes a sorted array of integers and a value to find. If the element is present in the array, the function should return its position (index). If the element is absent, return -1. The solution should be as efficient as possible.

public class Live {
    public static void main(String[] args) {
        // example usage
    }

    public static int search(int[] nums, int target) {
        // implementation
    }
}