Solve Search Insert Position Using Binary Search
Company: Amazon
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates proficiency in binary search, algorithmic implementation on sorted arrays, and understanding of time complexity and index management.
Constraints
- 0 <= len(nums) <= 100000
- nums is sorted in strictly increasing order
- All elements in nums are distinct
- -10^9 <= nums[i] <= 10^9
- -10^9 <= target <= 10^9
- Expected time complexity: O(log n)
- Do not use built-in bisect functions
Hints
- Maintain two pointers low and high bounding the current search range.
- Compute mid = (low + high) // 2 and compare nums[mid] with target.
- When the loop ends, low will be the correct insertion index.