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
Post a Comment