6. You are given an array of ids of prisoners.
The jail authority found that there are some prisoners of same id. Your
task is to help the authority in finding the common ids.
const readline = require('readline');
Input Description:
First line contains a number ‘n’ representing no of prisoners. Next line contains n space separated numbers.
First line contains a number ‘n’ representing no of prisoners. Next line contains n space separated numbers.
Output Description:
Print the ids which are not unique. Print -1 if all ids are unique
Print the ids which are not unique. Print -1 if all ids are unique
Sample Input : 7 1 1 11 121 131 141 98
Sample Output : 1
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 b = (userInput[1]);
var c = b.split(' ').map(val=>Number(val))
var d= "";
for(i=0;i<c.length;i++)
{
for(j=i+1;j<c.length;j++)
{if(c[i]==c[j])
d=d+c[i]+" "
}
}
e=d.split(" ")
console.log(e);
});
Comments
Post a Comment