You are given with an array of numbers, Your task is to print the difference of indices of largest and smallest number.All number are unique.
You are given with an array of numbers, Your task is to print the
difference of indices of largest and smallest number.All number are
unique.
Sample Input : 5 1 6 4 0 3
Sample Output : -2
const readline = require('readline');
const inp = readline.createInterface({
input: process.stdin
});
const userInput = [];
inp.on("line", (data) => {
userInput.push(data);
});
inp.on("close", () =>
{var a = (userInput[0]);
var b = a.split(" ").map(val=>Number(val))
var c =(userInput[1]);
var inp = c.split(" ").map(val=>Number(val))
var inparr = c.split(" ").map(val=>Number(val))
var arr =inparr.sort(function(a,b){return a-b})
var d= inp.indexOf(arr[0])
var e=inp.indexOf(arr[((arr.length)-1)])
console.log(e-d);
});
Comments
Post a Comment