Skip to main content

DEBUG

20.You are given with a list of size ‘n’. The list is imposed with a condition that all elements must be of range 0 to n-1.Your task is to rearrange the numbers such that arr[i] becomes arr[arr[i]].
 
Sample Input :
5
4 0 2 1 3

Sample Output :
3 4 2 0 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 myarr=[]
 for(i=0;i<a;i++)
 {myarr[i]=arr[arr[i]]}
 var final=myarr.join(" ")
 console.log(final);
 });
 
 
 
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


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=1;j<a;j++)
 {
     if(arr[i]==arr[j])
     arr.splice(i,1)
   
 }  
 }
 console.log(arr);
 });


 

Comments

Popular posts from this blog

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

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

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