Find First And Last Postion Of Element In Sorted Array

easy
1. Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value.
2. If target is not found in the array, return [-1, -1].
3. You must write an algorithm with O(log n) runtime complexity.

Input Format

Input is managed for you

Output Format

Output is managed for you

Constraints

0 <= nums.length <= 10^5
-10^9 <= nums[i] <= 10^9
nums is a non-decreasing array.
-10^9 <= target <= 10^9

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
7
2 2 3 3 3 4 5
3
Output
2 4
Previous
Count Inversions
Next
Max Sum In The Configuration

Related Questions