Skip to main content

Posts

Showing posts from May, 2020

Write a program to print the sum of the first K natural numbers.

Write a program to print the sum of the first K natural numbers. 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 = parseInt(data[0]);  var total=0;  for (i=0;i<=a;i++)  {total=total+i} console.log(total) });

Given 2 numbers N,M. Find their difference and check whether it is even or odd.

Given 2 numbers N,M. Find their difference and check whether it is even or odd. 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 = parseInt(data[0]);  var b = parseInt(data[1]); var c=(a-b) var d=Math.abs(c) if(d%2==0)  console.log("even")  else  console.log("odd") });

You are given a task to tell whether the number is pure or not. A pure number is a number whose sum of digits is multiple of 3.

You are given a task to tell whether the number is pure or not. A pure number is a number whose sum of digits is multiple of 3. 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[0]);  var b = a.split('');  var sum=0;  for(i=0;i<b.length;i++)  {sum=sum+ +b[i]}  if(sum%3==0)  console.log("yes")  else  console.log("not")  });  

Given a number N, print yes if the number is a multiple of 7 else print no.

Given a number N, print yes if the number is a multiple of 7 else print 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 = parseInt(data[0]);  if(a%7==0)  console.log("yes")  else  console.log("no") });

You are given a number ‘n’. You have to tell whether a number is great or not. A great number is a number whose sum of digits let (m) and product of digits let(j) when summed together gives the number back m+j=n

You are given a number ‘n’. You have to tell whether a number is great or not. A great number is a number whose sum of digits let (m) and product of digits let(j) when summed together gives the number back m+j=n 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 = parseInt(data[0]);  var b= String(a);  var c=[] for(i=0;i<b.length;i++)     {c[i]=b[i]}  var sum=0; for(i=0;i<c.length;i++) {sum=sum+Number(c[i])} var product=1; for(i=0;i<c.length;i++) {product=product*Number(c[i])} var d=sum+product if(d==a) console.log("Great");    else  console.log("no"); });

Given 3 numbers a,b,c print a*b mod c.

Given 3 numbers a,b,c print a*b mod c. 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 = parseFloat(data[0]);  var b= parseFloat(data[1]);  var c= parseFloat(data[2])  console.log((a*b)%c); });

concepts

Rahul is given a task to manipulate a string, He hired you as a developer your task is to delete all the repeating characters and print the result left. Input Description: You are given a string ‘s’ Output Description: Print the remaining string Sample Input : mississipie Sample Output : mpe     You are given a number with duplicate digits your task is to remove the immediate duplicate digits and print the result Input Description: You are given a long string of digits Output Description: Print the desired result print -1 if result length is 0 Sample Input : 1331 Sample Output : 11   Given a sentence and string S, find how many times S occurs in the given sentence.If S is not found in the sentence print -1 Input Size : |sentence| <= 1000000(complexity O(n)). Sample Testcase : INPUT I enjoy doing codekata codekata OUTPUT 1  

LARGEST INTEGER IN C

You are given with a string which comprises of some numbers. Your task is to find the largest integer by converting the string to the corresponding integer. Input Description: First line contains n denoting number of Test Cases. The first and only Line of testcase has the string Output Description: Print the largest number Sample Input : I was born on 12 october 1998. Sample Output : 1998   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.sort(); var b=[] for(i=0;i<a.length;i++) {b[i]=Number(a[i]) if(b[i]===NaN) break; } });  

pure or not

You are given a task to tell whether the number is pure or not. A pure number is a number whose sum of digits is multiple of 3. O(1) time and O(1) space Input Description: You are given a number n. Output Description: Print yes if it is pure else not Sample Input : 13 Sample Output : not     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[0]); var b = a.split(''); var sum=0; for(i=0;i<b.length;i++) {sum=sum+ +b[i]} if(sum%3==0) console.log("yes") else console.log("not") });

CODEKATA MATHS ELSE -1

Given a number N, print the odd digits in the number(space seperated) or print -1 if there is no odd digit in the given number. Input Size : N <= 100000 Sample Testcase : INPUT 2143 OUTPUT 1 3 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[0]);  var b = a.split('');  var c=[];  for(i=0;i<b.length;i++)  {if(Number(b[i])%2!==0)   c[i]=b[i]  else c[i]=0} for(i=0;i<c.length;i++) d=c.join(""); e=d.replace(/0/g,' ')  console.log(e);  });  

CODEKATA MATHS TICKET DISCOUNT

Assume that you are ticket verifier at a club. Your club has decided to give a special discount to the person(s) who are satisfying the following condition Condition:- If ticket number is divisible by date of month. You are eligible for a discount. Input Description: First line contains input ‘n’.Next line contains n space separated numbers denoting ticket numbers .Next line contains ‘k’ date of the month. Output Description: Print 1 if the ticket is eligible for discount else 0 Sample Input : 6 112 139 165 175 262 130 22 Sample Output : 0 0 0 0 0 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 = parseInt(userInput[0]); var b = userInput[1]; var bs=userInput[1].split(" "); var c = parseInt(userInput[2]) var d=[] for(i=0;i<a;i++) { if(N...

CODEKATA MATHS CAR ENGINE NO

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. Input Description: You are given a string ’s’ Output Description: Print the engine number Sample Input : HR05-AA-2669 Sample Output : 28     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("") var sum= +c[2]+ +c[3]+ +c[8]+ +c[9]+ +c[10]+ +c[11] console.log(sum) });  2 PRIVATE TEST CASE ERROR