-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path1553D-Backspace.js
More file actions
39 lines (36 loc) · 796 Bytes
/
1553D-Backspace.js
File metadata and controls
39 lines (36 loc) · 796 Bytes
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
function solution(s, t) {
const m = s.length, n = t.length
if (m < n) return false
let i = m - 1, j = n - 1
const delFirstOfS = (m - n) & 1
const smallestIdxOfS = delFirstOfS ? 1 : 0
while(i >= smallestIdxOfS && j >= 0) {
if(s[i] === t[j]) {
i--
j--
} else {
i -= 2
}
if (j < 0) return true
}
return false
}
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const input = [];
const resArr = []
rl.on("line", (line) => {
input.push(line);
if (input.length === 3) {
const t = input.pop()
const s = input.pop()
const res = solution(s, t)
resArr.push(res ? 'YES' : 'NO')
}
});
rl.on("close", () => {
resArr.forEach(e => console.log(e))
});