Sorted Position
Given a sorted list of distinct integers nums, return the index of target, or -1 if it is absent.
Requirements
- Run in time. Do not use
list.indexor thebisectmodule.
Examples
EXAMPLE WALKTHROUGHpresent
A guided view of the published example, not a trace of your code.
INPUT
[[-1,0,3,5,9,12],9]TASKsorted_position()
EXPECTED OUTPUT
4Start with the input values shown in this example.
Example 1 of 3
Input: nums = [-1,0,3,5,9,12], target = 9
Output: 4
Explanation: present
Input: nums = [-1,0,3,5,9,12], target = 2
Output: -1
Explanation: absent
Input: nums = [], target = 1
Output: -1
Explanation: empty
Hint 1
Keep a closed interval [lo, hi] and compare against the middle element.