You are given a number with duplicate digits your task is to remove the immediate duplicate digits and print the result
You are given a number with duplicate digits your task is to remove the immediate duplicate digits and print the result
Sample Input : 1331
Sample Output : 11
const readline = require('readline');
const inp = readline.createInterface({
input: process.stdin
});
const userInput = [];
inp.on("line", (data) => {
userInput.push(data);
});
inp.on("close", () => {
var data = userInput[0].split(" ");
var a = (data);
var b=data.join(' ');
var c=b.split("")
for(i=0;i<c.length;i++)
{if(c[i]==c[i+1])
c.splice(i,2)
}
d=c.join("")
console.log(d)
});
Comments
Post a Comment