dsa · easy

Search Insert Position

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

Arguments

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

Example

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

Constraints

0 <= nums.length <= 4*10^4 nums is sorted in non-decreasing order; all values unique 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