DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
easy
Binary Search

Binary Search

**Problem Statement:** Given the required input arguments, write an efficient algorithm to solve the **Binary Search** problem. Implement the required logic as specified by standard definitions for this classic algorithmic challenge. **Hint / Expected Approach:** Classic lo/hi/mid with integer overflow safe mid **Edge Cases to Consider:** - (1) Target not in array - (2) Single element - (3) Duplicate elements (first/last occurrence)

Examples

Example 1
Input: [-1,0,3,5,9,12], 9
Output: 4
Explanation: Classic
Example 2
Input: [-1,0,3,5,9,12], 2
Output: -1
Explanation: Not found
Example 3
Input: [1], 1
Output: 0
Explanation: Single element found

Constraints

  • ▪Input arguments are within valid ranges
  • ▪Optimize for execution speed
  • ▪Handle null/empty inputs gracefully

Watch Out For Edge Cases

  • ▪Target not in array
  • ▪Single element
  • ▪Duplicate elements (first/last occurrence)
Frequently Asked At
AmazonMicrosoftGoogleTCSWiproInfosys