Skip to content
CampusEduX

Binary Search

Easyjavapythonccppjavascript

Given a sorted array of distinct integers and a target value, find the target using binary search.

Input Format

The first line contains two integers N and target. The second line contains N space-separated integers in strictly increasing order.

Output Format

Print the index of target, or -1 if it is not present.

Related Problems

  • Linear Search
    Easy · java, python, c, cpp, javascript
    Solve Problem
  • First Occurrence in Sorted Array
    Easy · java, python, c, cpp, javascript
    Solve Problem
  • Last Occurrence in Sorted Array
    Easy · java, python, c, cpp, javascript
    Solve Problem

Input (stdin)

Output

Run your code to see output here...