Dodomeki
Sign in

20. Target Range

Easy

In a sorted array valores, find the first and last position of alvo. Return [ -1, -1 ] if the value does not exist; otherwise, return both indices, inclusive.

Example 1
Input: valores = [2,4,4,4,9], alvo = 4
Output: [1,3]
Example 2
Input: valores = [1,3,5,7], alvo = 6
Output: [-1,-1]
Constraints
  • 0 <= valores.length <= 10000
  • valores está em ordem não decrescente
  • -100000 <= valores[i], alvo <= 100000
Binary searchArrays
Caso 1
valores =
[2,4,4,4,9]
alvo =
4
Expected =
[1,3]
Caso 2
valores =
[1,3,5,7]
alvo =
6
Expected =
[-1,-1]

Run checks these 2 cases. Submit runs all 7, including hidden ones.