Find First and Last Occurrence of an Element
Medium

Problem Statement

Given a sorted array `nums` with possible duplicate elements, find the first and last occurrences of a given `target` value. If the target is not found in the array, return `[-1, -1]`.

Examples

1Example 1
Input:
{ "nums": [ 5, 7, 7, 8, 8, 10 ], "target": 8 }
Output:
[ 3, 4 ]
2Example 2
Input:
{ "nums": [ 5, 7, 7, 8, 8, 10 ], "target": 6 }
Output:
[ -1, -1 ]
3Example 3
Input:
{ "nums": [], "target": 0 }
Output:
[ -1, -1 ]
Loading...

Sign in to Run Code and Submit