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 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);
});
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
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
Post a Comment