Skip to content

Commit f9b9b6c

Browse files
authoredMar 30, 2025
Merge branch 'master' into sambabib-js-solutions
2 parents b7dc87f + efa91d4 commit f9b9b6c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1876
-601
lines changed
 

‎cpp/_916.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class Solution {
2+
public:
3+
vector<string> wordSubsets(vector<string>& words1, vector<string>& words2) {
4+
int maxCharFreq[26] = {0};
5+
int tempCharFreq[26];
6+
for (const auto& word : words2) {
7+
memset(tempCharFreq, 0, sizeof tempCharFreq);
8+
for (char ch : word) {
9+
tempCharFreq[ch - 'a']++;
10+
}
11+
for (int i = 0; i < 26; ++i) {
12+
maxCharFreq[i] = max(maxCharFreq[i], tempCharFreq[i]);
13+
}
14+
}
15+
vector<string> universalWords;
16+
for (const auto& word : words1) {
17+
memset(tempCharFreq, 0, sizeof tempCharFreq);
18+
for (char ch : word) {
19+
tempCharFreq[ch - 'a']++;
20+
}
21+
bool isUniversal = true;
22+
for (int i = 0; i < 26; ++i) {
23+
if (maxCharFreq[i] > tempCharFreq[i]) {
24+
isUniversal = false;
25+
break;
26+
}
27+
}
28+
if (isUniversal) {
29+
universalWords.emplace_back(word);
30+
}
31+
}
32+
return universalWords;
33+
}
34+
};

‎paginated_contents/algorithms/2nd_thousand/README.md

Lines changed: 275 additions & 274 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)