commit 4defcd7bc2eb7e6bb690e0a09da357fd3e45a075
parent c6f24b3b5331f4f026500d8df3100869b97c331a
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Sun, 24 Mar 2024 20:10:48 +0000
1 Random Problem
Diffstat:
2 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/Problems/0916.cpp b/Problems/0916.cpp
@@ -0,0 +1,31 @@
+class Solution {
+ public:
+ vector<string> wordSubsets(const vector<string> &words1, const vector<string> &words2) const {
+ const int n = size(words1), m = size(words2);
+ int count[26] = {0};
+ vector<string> res;
+
+ for (int i = 0; i < m; i++) {
+ int lcount[27] = {0};
+ for (char c : words2[i])
+ lcount[c - 'a']++;
+ for (int j = 0; j < 26; j++) {
+ count[j] = max(count[j], lcount[j]);
+ }
+ }
+
+ for (int i = 0; i < n; i++) {
+ int lcount[27] = {0};
+ for (char c : words1[i])
+ lcount[c - 'a']++;
+ for (int k = 0; k < 26; k++) {
+ if (lcount[k] < count[k]) goto next;
+ }
+
+ res.push_back(words1[i]);
+ next:;
+ }
+
+ return res;
+ }
+};
diff --git a/README.md b/README.md
@@ -539,6 +539,7 @@ for solving problems.
| 0909 | Medium | [Snakes and Ladders](Problems/0909.cpp) |
| 0912 | Medium | [Sort an Array](Problems/0912.cpp) |
| 0915 | Medium | [Partition Array into Disjoint Intervals](Problems/0915.cpp) |
+| 0916 | Medium | [Word Subsets](Problems/0916.cpp) |
| 0918 | Medium | [Maximum Sum Circular Subarray](Problems/0918.cpp) |
| 0919 | Medium | [Complete Binary Tree Inserter](Problems/0919.cpp) |
| 0920 | Hard | [Number of Music Playlists](Problems/0920.cpp) |