Practice Problems
0% completed
First index of element
Last index of element
Reverse the array
Rotate array
Find the kth largest and smallest element in an array
Sort an array containing 0,1 and 2 35

# First index of element

Difficulty: EASY

Problem Statement
Suggest Edit

#### Input Format:

``````The first line contains an integer N representing the size of the array.

The next line contains N space-separated integers representing the elements of the array.

The last line contains an integer 'x' whose index has to be found.
``````

#### Output Format:

``````The only line of the output prints the Index or -1.
``````
##### Constraints:
``````1 <= N <= 10^3
1 <= arr[i] <= 10^9
1 <= x < N
``````
##### Sample Input 1 :
``````8
7 5 2 11 2 43 1 1
2
``````
##### Sample Output 1 :
``````2
``````
##### Explanation of Sample Input 1:
``````2 is present twice in the input array and the first time it appears is at index 2.
``````
##### Sample Input 2 :
``````8
7 5 2 11 2 43 1 1
10
``````
##### Sample Output 2 :
``````-1
``````
##### Explanation of Sample Input 2:
``````10 is not present in the array so the output is -1.
``````   Console