Find Target Range
You are given a sorted list of integers arranged in ascending order and a target value. Your task is to find the first and last positions of that target in the list. If the target value does not exist in the list, return [-1, -1].
This challenge focuses on reasoning about the presence and boundaries of a value within a sorted sequence. Imagine you are searching through a list to find where a certain number begins and ends — like locating a group of identical items in a sorted row. Even if the number appears only once, both its starting and ending positions are the same index.
When the target does not appear at all, both the starting and ending indices should be -1. This problem helps develop an understanding of locating boundaries in ordered data while respecting sequence consistency and index logic.
Example 1:
Input: nums = [5,7,7,8,8,10], target = 8
Output: [3,4]
Explanation: The target 8 first appears at index 3 and last at index 4.
Example 2:
Input: nums = [5,7,7,8,8,10], target = 6
Output: [-1,-1]
Explanation: The target 6 does not exist in the list.
Example 3:
Input: nums = [2,2,2,2,2], target = 2
Output: [0,4]
Explanation: All elements are equal to the target, so it spans from index 0 to 4.
Related Problems
No related problems found
Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this problem.
