Dodomeki
Sign in

19. Insertion Position

Easy

Given an array numeros in ascending order and an integer alvo, return the index where alvo is located. If it is not present, return the index where it should be inserted to keep the order.

Example 1
Input: numeros = [1,3,6,9], alvo = 6
Output: 2
Example 2
Input: numeros = [1,3,6,9], alvo = 5
Output: 2
Constraints
  • 0 <= numeros.length <= 10000
  • -100000 <= numeros[i], alvo <= 100000
  • Os valores de numeros são distintos.
Binary searchArrays
Caso 1
numeros =
[1,3,6,9]
alvo =
6
Expected =
2
Caso 2
numeros =
[1,3,6,9]
alvo =
5
Expected =
2

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