Dodomeki
Sign in

64. Search in Rotated Array

Medium

An array of distinct integers, originally increasing, was circularly rotated. Return the index of alvo, or -1 if it is not present.

Example 1
Input: numeros = [11,14,18,2,5,8], alvo = 5
Output: 4
Example 2
Input: numeros = [6,9,1,3,4], alvo = 7
Output: -1
Constraints
  • 1 <= numeros.length <= 10000
  • Os valores são distintos
  • O array é uma rotação de uma sequência crescente
Binary searchArrays
Caso 1
numeros =
[11,14,18,2,5,8]
alvo =
5
Expected =
4
Caso 2
numeros =
[6,9,1,3,4]
alvo =
7
Expected =
-1

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