Skip to content

Commit

Permalink
Time: 12 ms (92.44%), Space: 53.7 MB (94.19%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit-S-Sahu committed Jan 10, 2025
1 parent 4be6a30 commit 40e1c61
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions 0916-word-subsets/0916-word-subsets.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class Solution {
public List<String> wordSubsets(String[] words1, String[] words2) {
int arr[] = new int[26];
List<String> ans = new ArrayList<>();
for (String word : words2){
int temp[] = new int[26];
for (int i = 0; i < word.length(); i++){
temp[word.charAt(i) - 'a']++;
}

for (int i = 0; i < 26; i++){
arr[i] = Math.max(arr[i], temp[i]);
}
}

for (String word : words1){
int temp[] = new int[26];
for (int i = 0; i < word.length(); i++){
temp[word.charAt(i) - 'a']++;
}
boolean flag = true;
for (int i = 0; i < 26; i++){
if (temp[i] < arr[i]) {
flag = false;
break;
}
}
if (flag) ans.add(word);
}
return ans;
}
}

0 comments on commit 40e1c61

Please sign in to comment.