hackerearth javascript solutions

Solutions on MaxInterview for hackerearth javascript solutions by the best coders in the world

showing results for - "hackerearth javascript solutions"
Aarón
21 Aug 2020
1function main(input) {
2    //Enter your code here
3    var data = input.split('\n');
4    var firstLine = data[0].split(' ');
5    var len = firstLine[0];
6    //process.stdout.write('length:'+len);
7    var toFind = firstLine[1];
8    //process.stdout.write('toFind:'+toFind);
9    //process.stdout.write('\n');
10    var arr = data[1].split(' '); 
11    //process.stdout.write(arr);
12    for(var i=len-1;i>=0;i--) {
13        if(arr[i] == toFind){
14            process.stdout.write(i+1);
15            return;
16        }
17    }
18    process.stdout.write(-1);
19}
20