54: Insert in a sorted array

Given a sorted array without duplicates and target item, return a position where to insert the target item. If the target already exists return its position, otherwise return a position where it should be

 

Example 1

Input:   array = [1, 2, 4], target = 2

Output: 1

Example 2

Input:   array = [1, 2, 4], target = 3

Output: 2
Difficulty:Easy
Topic:Binary Search
Problem #:54