You are given with an array. For each element present in the array your
task is to print the next smallest than that number. If it is not
smallest print -1
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 =Number(userInput[0]);
var inp =String(userInput[1]);
var arr =inp.split(" ").map(val=>Number(val))
var final=""
for(i=0;i<a;i++)
{
for(j=1;j<a;j++)
{arr[i]>arr[j]
final = final+arr[j]
} //From this line
}
console.log(final);
});
Sample Input : 7 10 7 9 3 2 1 15
Sample Output : 7 3 3 2 1 -1 -1
NOTE:
HOW TO BREAK THE ONCE I FIND THE SMALLEST NUMBER AFTER BREAK IT NEED TO CONTINUE FOR THE NEXT i VALUE
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 =Number(userInput[0]);
var inp =String(userInput[1]);
var arr =inp.split(" ").map(val=>Number(val))
var final=""
for(i=0;i<a;i++)
{
for(j=1;j<a;j++)
{arr[i]>arr[j]
final = final+arr[j]
} //From this line
}
console.log(final);
});
Comments
Post a Comment