Skip to main content

Posts

Showing posts from May, 2020

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

You are given with two arrays. Your task is to merge the array such that first array is in ascending order and second one in descending order.

You are given with two arrays. Your task is to merge the array such that first array is in ascending order and second one in descending order. Sample Input : 3 3 23 15 16 357 65 10 Sample Output : 15 16 23 357 65 10     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 c = (userInput[2]) var firstarr=b.split(" ").map(val=>Number(val)) var secondarr=c.split(" ").map(val=>Number(val)) var arr1=firstarr.sort(function(a,b){return a-b}) var arr2=secondarr.sort(function(a,b){return b-a}) var final=(arr1.concat(arr2)) console.log(final.join(" ")) });