dsa · easy

Search Insert Position

GreyOrangeArrayBinary SearchFoundation

Sorted distinct nums. Return the index of target, or where it **would** be inserted.

Arguments

**Example:** [1,3,5,6], target=52. target=21.

Constraints

0 <= nums.length <= 4*10^4 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
[1,3,5,6]
5

Expected:
2

Example 2

Input:
[1,3,5,6]
2

Expected:
1

Open in the Dojo editor