Skip to main content

Posts

18

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); });  
Recent posts

16

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...

you are given with array of numbers.you have to find whether array is beautiful or not. A beautiful array is an array whose sum of all numbers is divisible by 2, 3 and 5

you are given with array of numbers.you have to find whether array is beautiful or not. A beautiful array is an array whose sum of all numbers is divisible by 2, 3 and 5 Sample Input : 5 5 25 35 -5 30 Sample Output : 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 = (userInput[0]); var b =(userInput[1]); var arr = b.split(" ").map(val=>Number(val)) var sum=0 var ans=false; for(i=0;i<arr.length;i++) {sum=sum+arr[i]} if((sum%2==0)&&(sum%3==0)&&(sum%5==0)) console.log(1) else console.log(0); });  

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); });  

7

7. You are given with an circular array .Your task is calculate the difference between two consecutive number. And if difference is greater than ‘k’, print 1 else print 0 Input Description: You are given two numbers ‘n’, ’m’. Next line contains n space separated integers. Output Description: Print 1 if the difference is greater than ‘m’. Sample Input : 5 15 50 65 85 98 35 Sample Output : 0 1 0 1 0     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 diff = b[1] var c =(userInput[1]); var d = c.split(" ").map(val=>Number(val)) var final="" for(i=0;i<d.length;i++) { if(Math.abs((d[i+1]-d[i])) > diff) final=final+1+" "; else final=final+0+...

6

6. You are given an array of ids of prisoners. The jail authority found that there are some prisoners of same id. Your task is to help the authority in finding the common ids. Input Description: First line contains a number ‘n’ representing no of prisoners. Next line contains n space separated numbers. Output Description: Print the ids which are not unique. Print -1 if all ids are unique Sample Input : 7 1 1 11 121 131 141 98 Sample Output : 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 = parseInt(userInput[0]);  var b = (userInput[1]);  var c = b.split(' ').map(val=>Number(val))  var d= "";  for(i=0;i<c.length;i++)  {  for(j=i+1;j<c.length;j++)  {if(c[i]==c[j])   d=d+c[i]+" "    }  }  e=d.split(" ")  console.lo...

NEED TO COMPLETE

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   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);  });