Skip to main content

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

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