Second example is misleading
In this example:
- array = [1, 2, 3] and N = 3, but N is greater than the length of the array, so the result is -1.
N (3) is not greater than the length of the array (3) , but greater than the highest index of the array (2).