A number is given as input.Find the maximum number that can be formed using the digits. Input Size : N <= 10000000 Sample Testcase : INPUT 4123 OUTPUT 4321 const readline = require("readline"); const inp = readline.createInterface({ input: process.stdin }); const userInput = []; inp.on("line", (data) => { userInput.push(data); }); inp.on("close", () => { var inp = userInput[0]; var arr = inp.split("").map((val)=>Number(val)) var sarr = arr.sort(function(a,b){return b-a}); var ans =sarr.join("") console.log(ans) });
Joyal was given a sentence. His task is to delete the two words that comes together and print the sentence so that the words in the output sentence have distinct words compared to their adjacent words. If no words are present in the output sentence print -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 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)} } for(i=0;i<c.length;i++) {if(c[i]==c[i+1]) {c.splice(i,2)} } d=c.join("") console.log(d) });