Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 21, 2016 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/8899cb7587b0389e6ff6 to your computer and use it in GitHub Desktop.
Save jianminchen/8899cb7587b0389e6ff6 to your computer and use it in GitHub Desktop.
Two string - JavaScript, things I like: using j== first.length to determine YES/ NO, the big problem of coding - repeat same code in if/ else code.
function processData(input) {
//Enter your code here
var inputs = input.split('\n');
var t = parseInt(inputs[0]);
for(var i = 0; i < t; i++ ){
var first = inputs[2*i+1];
var second = inputs[2*i+2];
if(first.length < second.length){
for(var j = 0; j <first.length; j++){
if(second.indexOf(first[j]) != -1)
break;
}
if(j==first.length)
console.log("NO");
else
console.log("YES");
}else{
for(var j = 0; j <second.length; j++){
if(first.indexOf(second[j]) != -1)
break;
}
if(j==second.length)
console.log("NO");
else
console.log("YES");
}
}
}
process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
_input += input;
});
process.stdin.on("end", function () {
processData(_input);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment