Binary Search to find X in Sorted Array
Learning 1D Array Binary Search DSA practice problem on Onlearn.
Difficulty: easy.
Topics: Binary Search Algorithm: Concept, Implementation, and Complexity Analysis, Binary Search, Linear Search, Arrays, Recursion, Time Complexity, Space Complexity, Big O Notation, iterative algorithms, array, divide and conquer, general programming, recursion base case, search algorithms, binary search, recursion, time complexity analysis, Search Pointers, Specific Time Complexities.
Problem Statement You are given a sorted array of distinct integers and a target value. Your task is to search for the target in the given array. Input Specification An integer array nums sorted in ascending order. An integer target. Output Specification Return the index of the target in nums if it exists. If the target is not found, return 1. Sample Test Cases Sample 1 Input: Output: Sample 2 Input: Output: