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

Find First and Last Position

**Problem Statement:** Given the required input arguments, write an efficient algorithm to solve the **Find First and Last Position** problem. Implement the required logic as specified by standard definitions for this classic algorithmic challenge. **Hint / Expected Approach:** Two binary searches: leftmost and rightmost **Edge Cases to Consider:** - (1) Target not found - (2) All elements are target - (3) Single element array

Examples

Example 1
Input: [5,7,7,8,8,10], 8
Output: [3,4]
Explanation: Classic
Example 2
Input: [5,7,7,8,8,10], 6
Output: [-1,-1]
Explanation: Not found
Example 3
Input: [], 0
Output: [-1,-1]
Explanation: Empty

Constraints

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

Watch Out For Edge Cases

  • ▪Target not found
  • ▪All elements are target
  • ▪Single element array
Frequently Asked At
AmazonMicrosoftGoogleAdobeTCS