← 返回 bytedance 的题目列表Find the Smallest Index to Insert a Value in a Sorted Array
类型:online_judge
Given a non-decreasing (sorted ascending) array nums (may contain duplicates) and an integer target, return the smallest index i such that inserting target at index i keeps the array sorted.
Equivalently, return the smallest i with nums[i] >= target; if no such index exists, return len(nums).
Input:
Line 1: integer n
Line 2: n integers (sorted)
Line 3: integer target
Output: the index
Constraints: 0 <= n <= 2e5, values in [-1e9, 1e9]
Example Input:
4
1 3 3 5
3
Output:
1
Example
Input
4
1 3 3 5
3
Output
1