1
var wordPattern = function (pattern, s) {
2
let wordArray = s.split(" ");
3
if (wordArray.length !== pattern.length) return false;
4

5
let hm = {};
6
let hs = new Set();
7

8
for (let index in pattern) {
9
let word = wordArray[index];
10
let char = pattern[index];
11

12
if (hm[char] !== undefined) {
13
if (hm[char] !== word) return false;
14
} else {
15
if (hs.has(word)) return false; // Duplicate Occurence of word on first occurrence of a char
16
hm[char] = word;
17
hs.add(word);
18
}
19
}
20

21
return true;
22
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0