Skip to main content

Posts

Showing posts from May, 2020

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

Given a string S, print the 1st and 3rd character of the string (chracter index starts from 1).

Given a string S, print the 1st and 3rd character of the string (chracter index starts from 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 = String(data[0]);  var b=a.split('')  var c =""  var c=b[0]+b[2]  console.log(c);  });

You are given some words all in lower case letters your task is to print them in sorted order.

You are given some words all in lower case letters your task is to print them in sorted order. 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 = String(userInput[0]);  var b = a.split(' ')  var c = b.sort()  var d = c.join(' ')  console.log(d);  });

Given a string S, print it after changing the middle element to * (if the length of the string is even, change the 2 middle elements to *). Sample Testcase : INPUT hello OUTPUT he*lo

Given a string S, print it after changing the middle element to * (if the length of the string is even, change the 2 middle elements to *). Sample Testcase : INPUT hello OUTPUT he*lo 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 = b.length  var d = Math.round(c/2) { if(c%2!==0)  b[d-1]="*"  else  b[d]="*";   b[d-1]="*" }  var e=b.join('')  console.log(e);  });

Ria is a 5 year old girl. Her mother wants to teach her how to sort words in the same order that they appear in a dictionary. She decides to write a program to sort a given set of strings based on their alphabetical order. Help Ria’s mother to complete the program.

Ria is a 5 year old girl. Her mother wants to teach her how to sort words in the same order that they appear in a dictionary. She decides to write a program to sort a given set of strings based on their alphabetical order. Help Ria’s mother to complete the program. 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 = String(userInput[1]);  var c = b.split(' ')  var d = c.sort()  var e = d.join(' ')  console.log(e);  });

DEBUG

62.Given a number N and an array of N strings, find if two consecutive words are same. Input Size : N <= 1000 Sample Testcase : INPUT 5 code overload vishal sundar anish OUTPUT no ONE TESTCASE PASSED const readline = require("readline"); const inp = readline.createInterface({   input: process.stdin }); const userInput = []; inp.on("line", (data) => {   userInput.push(data); }); inp.on("close", () => {    var ans;   var N = Number(userInput[0]);   for(i=1;i<=N;i++)   {if(userInput[i]===(userInput[i+1]))    {ans= "yes";    return;}    else    {ans="no"}}     console.log(ans)   });

CONCEPTS 2

13. You are given a string. You have to print “Wonder” if the string is wonderful and -1 if it is not. A wonderful string is a string,which is made up of exactly 3 different characters. Input Description: You are given a string Output Description: Print “Wonder” if it is wonderful and -1 if it is not Sample Input : aabbcc Sample Output : Wonder     16.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.  Sample Input : I was born on 12 october 1998. Sample Output : 1998      

Given a string 'S' print the sum of weight of the String. A weight of character is defined as the ASCII value of corresponding character.

Given a string 'S' print the sum of weight of the String. A weight of character is defined as the ASCII value of corresponding character. 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 sum=0; for (i=0;i<a.length;i++) sum=sum+a.charCodeAt(i) console.log(sum) });

You are given a ‘true’ string. String is called true if weight of string is multiple of 8. Your task is to tell whether a string can be declared True or Not. Weight of string is the sum of ASCII value of Vowel character(s) present in the string.

 You are given a ‘true’ string. String is called true if weight of string is multiple of 8. Your task is to tell whether a string can be declared True or Not. Weight of string is the sum of ASCII value of Vowel character(s) present in the string. 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 sum=0; for (i=0;i<a.length;i++) {sum=sum+a.charCodeAt(i)} if(sum%8==0) console.log(1) else   console.log(0) });

Radha newly learnt about palindromic strings.A palindromic string is a string which is same when read from left to right and also from right to left.Help her in implementing the logic

Radha newly learnt about palindromic strings.A palindromic string is a string which is same when read from left to right and also from right to left.Help her in implementing the logic 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=b.length  var count=0  for(i=0;i<b.length;i++) {if(a[i]===a[c-(i+1)])  count++  }  if(count==c)  console.log(1)  else  console.log(0) });  

Given a string S, print 'yes' if it has a vowel in it else print 'no'. Sample Testcase : INPUT codekata OUTPUT yes

Given a string S, print 'yes' if it has a vowel in it else print 'no'. Sample Testcase : INPUT codekata 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 = String(data[0]);  var b=a.split("")  var v;  var count=false  for(v of b) {  if(v == "a" || v == "e" || v == "i" || v == "o" || v == "u" || v == "A" || v == "E" || v == "I" || v == "O" || v == "U")  count=true }  if(count)  console.log('yes')  else  console.log('no') });  

CONCEPTS -1

2. 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. CHECK WITH 4 Sample Input : mississipie Sample Output : mpe       3.You are given a string.Your task is to print only the consonants present in the string without affecting the sentence spacings if present. If no consonants are present print -1   Sample Input : I am shrey Sample Output : m shry     4. 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     9.you are given a string made up of parenthesis only.Your task is to check whether parenthesis are balanced or not.If they are balanced print 1 else print 0  Sample Input : {({})} Sample Output : 1     10.Joyal was given a sentence. His task is to delete the two word...

Jennyfer is fond of strings. She wants to read the character from right to left (reverse the string), so she wants you to design a suitable algorithm which satisfy her desire.

 Jennyfer is fond of strings. She wants to read the character from right to left (reverse the string), so she wants you to design a suitable algorithm which satisfy her desire. Sample Input : jennyfer Sample Output : Refynnej     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= b.reverse(); var d= c.join(''); var e = d.slice(0,1) var f= d.slice(1,d.length) var g=e.toUpperCase() console.log(g+f) });