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.
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’.
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+" "
}
console.log(final);
});
Comments
Post a Comment