We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3f00c9c commit 15c272dCopy full SHA for 15c272d
0901-1000/0916_word_subsets.rb
@@ -0,0 +1,18 @@
1
+# @param {String[]} words1
2
+# @param {String[]} words2
3
+# @return {String[]}
4
+def word_subsets(words1, words2)
5
+ words2_max_freq = Hash.new(0)
6
+ words2.each { |word|
7
+ word.chars.tally.each { |c, count|
8
+ words2_max_freq[c] = [words2_max_freq[c], count].max
9
+ }
10
11
+
12
+ words1.select { |word|
13
+ word1_freq = word.chars.tally
14
+ words2_max_freq.all? { |c, max_count|
15
+ word1_freq.has_key?(c) && word1_freq[c] >= max_count
16
17
18
+end
0 commit comments