Sale
Summer Offer: $190/yr $99/yr
00 : 00 : 00 : 00
Get this deal
Backend Engineer Senior programming

Write a function that finds the first and last position of a target value in a sorted array. If the target is not found, return [-1, -1].


Function Signature


def search_range(nums: List[int], target: int) -> List[int]:

Constraints


  • 0 <= nums.length <= 10^5

  • -10^9 <= nums[i], target <= 10^9


Examples


1. Input: search_range([5,7,7,8,8,10], 8)
Output: [3, 4]
2. Input: search_range([5,7,7,8,8,10], 6)
Output: [-1, -1]
Suggested Answer

Trusted by 100+ professionals preparing for interviews

Trusted by 100+ professionals 50+ Company Question Banks 5+ Supported Languages

Practice More Questions Like This

Generate unlimited interview questions with structured answers, code runner, and AI-powered walkthroughs.

Get Started Free
Link copied to clipboard