Posts

Showing posts from June, 2020

DATA

BITWISE OPERATOR 5 13 15 CONCEPT 9 temp 14,26 22 23 24 TESTCASE 16 18 21

Given a number N followed by N numbers.Find the smallest number and largest number and print both the indices(1 based indexing).

Given a number N followed by N numbers.Find the smallest number and largest number and print both the indices(1 based indexing). Input Size : N <= 100000 Sample Testcase : INPUT 5 1 2 3 4 5 OUTPUT 1 5 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 outarr =[]  var b = (userInput[1]);  var arr = b.split(" ").map((val)=>Number(val))  var sarr = []  for(i=0;i<arr.length;i++)  {sarr[i]=arr[i]}  sarr.sort(function(a,b){return a-b})  for(i=0;i<arr.length;i++)  {if(sarr[0]==arr[i])  {outarr[0]=1+i}  if(sarr[(arr.length)-1]==arr[i])  {outarr[1]=1+i}  }  var out = outarr.join(" ")  console.log(out)    });

Given a string S consisting of 2 words reverse the order of two words .

Given a string S consisting of 2 words reverse the order of two words . Input Size : |S| <= 10000000 Sample Testcase : INPUT hello world OUTPUT world hello 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.reverse();  var c= a.join(" "); console.log(c) });

Given 3 numbers N , L and R. Print 'yes' if N is between L and R else print 'no'.

Given 3 numbers N , L and R. Print 'yes' if N is between L and R else print 'no'. Sample Testcase : INPUT 3 2 6 OUTPUT yes 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 c= b.split(" ")  if(+c[0]<a &&  a+c[1])  console.log("yes")  else  console.log("no")  });

Given 3 numbers A,B,C print 'yes' if they can form the sides of a right angled triangle,otherwise 'no'.

Given 3 numbers A,B,C print 'yes' if they can form the sides of a right angled triangle,otherwise 'no'. Input Size : A,B,C <= 100000 Sample Testcase : INPUT 3 4 5 OUTPUT yes 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 = parseInt(data[2]);  var d = (a*a)+(b*b)  var e = c*c;  if(d==e)  console.log('yes')    else  console.log('no') });

Given base(B) and height(H) of a triangle find its area.

Given base(B) and height(H) of a triangle find its area. Input Size : N <= 1000000 Sample Testcase : INPUT 2 4 OUTPUT 4 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]); console.log(0.5*a*b) });

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. Input Size : n <= 100000 Sample Testcase : INPUT 3 OUTPUT 6 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. Print 'yes' if their product is a perfect square else print 'no'.

Given 2 numbers N,M. Print 'yes' if their product is a perfect square else print 'no'. Sample Testcase : INPUT 5 5 OUTPUT yes 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]);  if(a==b) console.log('yes');  else console.log('no') });

Given 2 numbers N and K followed by N elements,print the number of repetition of K otherwise print '-1'

Given 2 numbers N and K followed by N elements,print the number of repetition of K otherwise print '-1' if the element not found. Sample Testcase : INPUT 6 2 1 2 3 5 7 8 OUTPUT 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 inp = a.split(' '); var k = inp[1]  var b = (userInput[1]);  var arr = b.split(" ")  var flag =0  for(i=0;i<arr.length;i++)  {if(arr[i]==k)  flag++}   if(flag>1)  console.log(flag)  else if (flag==1)  console.log(0)  else if(flag==0)  console.log(-1)  });

Given numbers A,B find A^B.

Given numbers A,B find A^B. Input Size : 1 <= A <= 5 <= B <= 50 Sample Testcase : INPUT 3 4 OUTPUT 81 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) console.log(c); });

Find the minimum among 10 numbers.

Find the minimum among 10 numbers. Sample Testcase : INPUT 5 4 3 2 1 7 6 10 8 9 OUTPUT 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 c=data.sort(function (a,b){return a-b}); console.log(c[0]); });

Given 2 numbers N and K followed by elements of N .Print 'yes' if K exists else print 'no'.

Given 2 numbers N and K followed by elements of N .Print 'yes' if K exists else print 'no'. Sample Testcase : INPUT 4 2 1 2 3 3 OUTPUT yes 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 inp = a.split(' '); var k = inp[1]  var b = (userInput[1]);  var arr = b.split(" ")  var out = arr.includes((k))  if(out)  console.log('yes')  else  console.log('no')  });

Given 2 numbers N and M add both the numbers and check whether the sum is odd or even.

Given 2 numbers N and M add both the numbers and check whether the sum is odd or even. Sample Testcase : INPUT 9 2 OUTPUT 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 = parseFloat(data[0]); var b = parseFloat(data[1]) var c= a+b; if(c%2==0) console.log("even") else   console.log("odd")  });

Kabali is a brave warrior who with his group of young ninjas moves from one place to another to fight against his opponents. Before Fighting he just calculates one thing, the difference between his ninja number and the opponent's ninja number. From this difference he decides whether to fight or not. Kabali's ninja number is never greater than his opponent.

Kabali is a brave warrior who with his group of young ninjas moves from one place to another to fight against his opponents. Before Fighting he just calculates one thing, the difference between his ninja number and the opponent's ninja number. From this difference he decides whether to fight or not. Kabali's ninja number is never greater than his opponent. Input The input contains two numbers in every line. These two numbers in each line denotes the number ninjas in Kabali's clan and his opponent's clan . print the absolute difference of number of ninjas between Kabali's clan and his opponent's clan. Each output should be in seperate line. Sample Testcase : INPUT 100 200 OUTPUT 100 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(" ...