Find First and Last Position of Element in Sorted Array
Problem Statement
Given an array of integers `nums` sorted in non-decreasing order, find the starting and ending position of a given `target` value.
If `target` is not found in the array, return `[-1, -1]`.
You must write an algorithm with `O(log n)` runtime complexity.
### Input Format
- First line contains space-separated integers representing `nums`. (Can be empty).
- Second line contains an integer `target`.
### Output Format
- Print two space-separated integers representing the first and last indices of `target`, or `-1 -1` if not found.
### Constraints
- `0 <= nums.length <= 10^5`
- `-10^9 <= nums[i] <= 10^9`
- `nums` is a non-decreasing array.
- `-10^9 <= target <= 10^9`
Sample Cases
Example 1Sample Case
Input: 5 7 7 8 8 10
8
Output: 3 4
Example 2Sample Case
Input: 5 7 7 8 8 10
6
Output: -1 -1
Example 3Sample Case
Input: 5 7 7 8 8 10
15
Output: -1 -1
Example 4Sample Case
Input: 5 7 7
12
Output: -1 -1
Constraints
Runtime Limit: 2000 ms per test batch
Memory Limit: 256 MB
Standard I/O stream reading
Official submissions are evaluated against hidden test cases on the server to verify time & memory complexity.