-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhashes-twoStrings.js
More file actions
77 lines (56 loc) · 1.39 KB
/
Copy pathhashes-twoStrings.js
File metadata and controls
77 lines (56 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// https://www.hackerrank.com/challenges/two-strings/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=dictionaries-hashmaps
'use strict';
const fs = require('fs');
const {
mainModule
} = require('process');
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
function twoStrings(s1, s2) {
// console.log('-------------------------')
const set1 = new Set(s1.split(''))
const set2 = new Set(s2.split(''))
let isSubs = false
let smaller = set1
let greater = set2
if (set2.size < set1.size) {
smaller = set2
greater = set1
}
for (let member of smaller) {
// console.log(member)
if (greater.has(member)) {
isSubs = true
break
}
}
if (isSubs) {
return 'YES'
} else {
return 'NO'
}
//console.log(set1,set2)
}
function main() {
const q = parseInt(readLine(), 10);
for (let qItr = 0; qItr < q; qItr++) {
const s1 = readLine();
const s2 = readLine();
let result = twoStrings(s1, s2);
}
}
function readLine() {
return inputString[currentLine++];
}
let reader = fs.createReadStream('twoString-input00.txt');
reader.on('data', function (chunk) {
inputString += chunk.toString()
});
reader.on("end", () => {
inputString = inputString.replace(/\s*$/, '')
.split('\n')
.map(str => str.replace(/\s*$/, ''));
main();
});