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 Sample Input : 7 10 7 9 3 2 1 15 Sample Output : 7 3 3 2 1 -1 -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=i+1;j<a;j++) { if(arr[i]>arr[j]) {final = final+arr[j] break} if(!arr[i]>arr[j]) {final = final+"-1" break} } } console.log(final); });
You are a passport issuer, but due to some problems in the system, there are redundant passport numbers. Your task is to delete all the duplicate passport numbers. You are given a list of passport numbers. Sample Input : 5 A23 B56 B56 C79 D16 Sample Output : A23 B56 C79 D16 Sample Input : 5 A23 B56 B56 C79 D16 Sample Output : B56 B56 C79 B56 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 inp = String(userInput[1]); var arr = inp.split(" ") for(i=0;i<a;i++) { for(j=i+1;j<a;j++) { if(arr[i]==arr[j]) arr.splice(i,1) i-- //try without this line console.log(arr) } } var str=arr.join...