Back to problems

Binary Search (basic)

Algorithm · Rokt · Easy

Problem: Basic Binary Search You are given an integer array nums whose elements are sorted in non-decreasing order, along with an integer target. Locate the target in the array. When target appears in nums, print any corresponding 0-based index. When the array contains no target, print -1. Input (stdin) The first line contains the array length, n. The second line contains the n integers in the sorted array nums. The third line contains the integer target. Output (stdout)…

Checking your access…