PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates proficiency in binary search, algorithmic implementation on sorted arrays, and understanding of time complexity and index management.

  • medium
  • Amazon
  • Coding & Algorithms
  • Data Scientist

Solve Search Insert Position Using Binary Search

Company: Amazon

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

##### Scenario Live coding round for an Amazon Applied Scientist position; candidate must solve LeetCode 35 (Search Insert Position) without helper libraries. ##### Question Given a sorted array of distinct integers nums and an integer target, return the index if target exists; otherwise return the index where it would be inserted to keep order. Implement the solution using an explicit binary search (no built-in bisect). ##### Hints Iterative or recursive binary search, O(log n) time, manage low/high pointers and insertion position when loop exits.

Quick Answer: This question evaluates proficiency in binary search, algorithmic implementation on sorted arrays, and understanding of time complexity and index management.

Given a sorted array of distinct integers nums and an integer target, return the index of target if it is present. Otherwise, return the index where target should be inserted to maintain ascending order. Implement the solution using an explicit binary search (do not use built-in bisect).

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

  1. Maintain two pointers low and high bounding the current search range.
  2. Compute mid = (low + high) // 2 and compare nums[mid] with target.
  3. When the loop ends, low will be the correct insertion index.
Last updated: Mar 29, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Find Two-Word Compound Words - Amazon (hard)
  • Minimum Path Length Through a Grid With One Allowed Cell Conversion - Amazon (medium)
  • Circular Drone Hub Delivery Route - Amazon (hard)
  • Leaf Domain Cumulative Scores - Amazon (medium)
  • Kth Largest Perfect Binary Subtree - Amazon (medium)