Skip to content

Commit 25dafe5

Browse files
committed
Add solution #1452
1 parent 398b571 commit 25dafe5

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,308 LeetCode solutions in JavaScript
1+
# 1,309 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1109,6 +1109,7 @@
11091109
1449|[Form Largest Integer With Digits That Add up to Target](./solutions/1449-form-largest-integer-with-digits-that-add-up-to-target.js)|Hard|
11101110
1450|[Number of Students Doing Homework at a Given Time](./solutions/1450-number-of-students-doing-homework-at-a-given-time.js)|Easy|
11111111
1451|[Rearrange Words in a Sentence](./solutions/1451-rearrange-words-in-a-sentence.js)|Medium|
1112+
1452|[People Whose List of Favorite Companies Is Not a Subset of Another List](./solutions/1452-people-whose-list-of-favorite-companies-is-not-a-subset-of-another-list.js)|Medium|
11121113
1455|[Check If a Word Occurs As a Prefix of Any Word in a Sentence](./solutions/1455-check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.js)|Easy|
11131114
1456|[Maximum Number of Vowels in a Substring of Given Length](./solutions/1456-maximum-number-of-vowels-in-a-substring-of-given-length.js)|Medium|
11141115
1460|[Make Two Arrays Equal by Reversing Sub-arrays](./solutions/1460-make-two-arrays-equal-by-reversing-sub-arrays.js)|Easy|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* 1452. People Whose List of Favorite Companies Is Not a Subset of Another List
3+
* https://leetcode.com/problems/people-whose-list-of-favorite-companies-is-not-a-subset-of-another-list/
4+
* Difficulty: Medium
5+
*
6+
* Given the array favoriteCompanies where favoriteCompanies[i] is the list of favorites companies
7+
* for the ith person (indexed from 0).
8+
*
9+
* Return the indices of people whose list of favorite companies is not a subset of any other list
10+
* of favorites companies. You must return the indices in increasing order.
11+
*/
12+
13+
/**
14+
* @param {string[][]} favoriteCompanies
15+
* @return {number[]}
16+
*/
17+
var peopleIndexes = function(favoriteCompanies) {
18+
const companySets = favoriteCompanies.map(companies => new Set(companies));
19+
const result = [];
20+
21+
for (let i = 0; i < favoriteCompanies.length; i++) {
22+
let isSubset = false;
23+
for (let j = 0; j < favoriteCompanies.length; j++) {
24+
if (i !== j && isSubsetOf(companySets[i], companySets[j])) {
25+
isSubset = true;
26+
break;
27+
}
28+
}
29+
if (!isSubset) {
30+
result.push(i);
31+
}
32+
}
33+
34+
return result;
35+
36+
function isSubsetOf(setA, setB) {
37+
if (setA.size > setB.size) return false;
38+
for (const item of setA) {
39+
if (!setB.has(item)) return false;
40+
}
41+
return true;
42+
}
43+
};

0 commit comments

Comments
 (0)