Skip to main content

Posts

A number is given as input.Find the maximum number that can be formed using the digits.

  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)   });
Recent posts

DOUBTS

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)  });

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) });

In XYZ country there is rule that car’s engine no. depends upon car’ number plate. Engine no is sum of all the integers present on car’s Number plate.The issuing authority has hired you in order to provide engine no. to the cars.Your task is to develop an algorithm which takes input as in form of string(Number plate) and gives back Engine number.

In XYZ country there is rule that car’s engine no. depends upon car’ number plate. Engine no is sum of all the integers present on car’s Number plate.The issuing authority has hired you in order to provide engine no. to the cars.Your task is to develop an algorithm which takes input as in form of string(Number plate) and gives back Engine number. 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("").map(val=>Number(val))  var sum=0;  for(i=0;i<c.length;i++)  {d=c[i]  if(isNaN (d))  sum =sum;  else  sum= sum+d  }   console.log(sum)  });

You are given a string ‘s’.Your task is to find whether string is beautiful or not. A string is said to be beautiful whenever string is made up of only three characters. All the three characters must be distinct.Print true if string is beautiful and false when it is not beautiful

You are given a string ‘s’.Your task is to find whether string is beautiful or not. A string is said to be beautiful whenever string is made up of only three characters. All the three characters must be distinct.Print true if string is beautiful and false when it is not beautiful  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 = String(data[0]);  var b = a.split('');  var c= true;  if(b.length==3)  c=true;  if(b[0]==b[1]||b[1]==b[2]||b[0]==b[2])  c=false;  if(c)  console.log('1');  else  console.log('0')  });

You are given a string ‘s’. Your task is to tell whether string is beautiful or not.A beautiful string is a string in which String starts with ‘a’ or ‘A’ and middle element is either ‘m’ or ‘M’ and last element is ‘z’or ‘Z’

You are given a string ‘s’. Your task is to tell whether string is beautiful or not.A beautiful string is a string in which String starts with ‘a’ or ‘A’ and middle element is either ‘m’ or ‘M’ and last element is ‘z’or ‘Z’ 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 = a.length  var c= Math.round(b/2) if((a[0]=="a"||a[0]=="A")&&(a[c-1]=="m"||a[c-1]=="M")&&(a[b-1]=="z"||a[b-1]=="Z"))  console.log(1)  else  console.log(0) });

Given a day, print 'yes' if it is a holiday otherwise print'no'.Assume that weekend days are holidays

Given a day, print 'yes' if it is a holiday otherwise print'no'.Assume that weekend days are holidays Sample Testcase : INPUT saturday OUTPUT yes INPUT monday OUTPUT no 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 = String(data[0])  if(a=='saturday'||a=='sunday')  console.log('yes')  else    console.log('no')  });