Given a number N followed by N numbers.Find the smallest number and largest number and print both the indices(1 based indexing).

Given a number N followed by N numbers.Find the smallest number and largest number and print both the indices(1 based indexing).
Input Size : N <= 100000
Sample Testcase :
INPUT
5
1 2 3 4 5
OUTPUT
1 5

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 = parseInt(userInput[0]);
var outarr =[]
 var b = (userInput[1]);
 var arr = b.split(" ").map((val)=>Number(val))
 var sarr = []
 for(i=0;i<arr.length;i++)
 {sarr[i]=arr[i]}
 sarr.sort(function(a,b){return a-b})
 for(i=0;i<arr.length;i++)
 {if(sarr[0]==arr[i])
 {outarr[0]=1+i}
 if(sarr[(arr.length)-1]==arr[i])
 {outarr[1]=1+i}
 }
 var out = outarr.join(" ")
 console.log(out)
 
 });

Comments

Popular posts from this blog

Kabali is a brave warrior who with his group of young ninjas moves from one place to another to fight against his opponents. Before Fighting he just calculates one thing, the difference between his ninja number and the opponent's ninja number. From this difference he decides whether to fight or not. Kabali's ninja number is never greater than his opponent.

Given 2 numbers N,M. Print 'yes' if their product is a perfect square else print 'no'.

Given 2 numbers N and M add both the numbers and check whether the sum is odd or even.