We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 6b87d5d + 15c272d commit 2f4dd60Copy full SHA for 2f4dd60
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