Given 2 numbers N and K followed by N elements,print the number of repetition of K otherwise print '-1'
Given 2 numbers N and K followed by N elements,print the number of
repetition of K otherwise print '-1' if the element not found.
Sample Testcase :
INPUT
6 2
1 2 3 5 7 8
OUTPUT
Sample Testcase :
INPUT
6 2
1 2 3 5 7 8
OUTPUT
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 inp = a.split(' ');
var k = inp[1]
var b = (userInput[1]);
var arr = b.split(" ")
var flag =0
for(i=0;i<arr.length;i++)
{if(arr[i]==k)
flag++}
if(flag>1)
console.log(flag)
else if (flag==1)
console.log(0)
else if(flag==0)
console.log(-1)
});
const inp = readline.createInterface({
input: process.stdin
});
const userInput = [];
inp.on("line", (data) => {
userInput.push(data);
});
inp.on("close", () =>
{var a = (userInput[0]);
var inp = a.split(' ');
var k = inp[1]
var b = (userInput[1]);
var arr = b.split(" ")
var flag =0
for(i=0;i<arr.length;i++)
{if(arr[i]==k)
flag++}
if(flag>1)
console.log(flag)
else if (flag==1)
console.log(0)
else if(flag==0)
console.log(-1)
});
Comments
Post a Comment