Skip to content

Commit 8a95fdf

Browse files
authored
Create 2076-process-restricted-friend-requests.js
1 parent 4a0899b commit 8a95fdf

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @param {number} n
3+
* @param {number[][]} restrictions
4+
* @param {number[][]} requests
5+
* @return {boolean[]}
6+
*/
7+
var friendRequests = function(n, restrictions, requests) {
8+
function validation(arr) {
9+
for (const [x, y] of restrictions) {
10+
if (arr[x] == arr[y]) return false
11+
}
12+
13+
return true
14+
}
15+
16+
17+
18+
let groupId = []
19+
for(let i = 0; i < n; i++) groupId.push(i)
20+
21+
22+
const ans = []
23+
for(let [u, v] of requests) {
24+
if (v < u) [u, v] = [v, u]
25+
const tmp = groupId.slice()
26+
27+
for(let i = 0; i < n; i++) {
28+
if (tmp[i] == groupId[v]) tmp[i] = groupId[u]
29+
}
30+
31+
if (validation(tmp)) {
32+
ans.push(true)
33+
groupId = tmp
34+
} else ans.push(false)
35+
}
36+
37+
38+
return ans
39+
};
40+

0 commit comments

Comments
 (0)