LeetCode 34 Find First and Last Position of Element - Problem Statement

The problem

Given a sorted array of integers and a target value, find the starting and ending position of the target. Return [-1, -1] if the target is not found.

With nums = [5, 7, 7, 8, 8, 10] and target = 8, the answer is [3, 4]. The value 8 first appears at index 3 and last appears at index 4.

You must achieve O(logn)O(\log n) runtime. How can binary search find boundaries instead of just existence?

Constraints: 0n1050 \le n \le 10^5. Array is sorted in non-decreasing order.