We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent adceb56 commit a08ce3cCopy full SHA for a08ce3c
870-advantage-shuffle.js
@@ -0,0 +1,28 @@
1
+/**
2
+ * @param {number[]} A
3
+ * @param {number[]} B
4
+ * @return {number[]}
5
+ */
6
+function advantageCount(aArr, B) {
7
+ const A = aArr.sort((a, b) => a - b)
8
+ const n = A.length
9
+ const res = []
10
+ let pq = []
11
+ for(let i = 0; i < n; i++) {
12
+ pq.push([B[i], i])
13
+ }
14
+ pq.sort((a, b) => b[0] - a[0])
15
+ let lo = 0
16
+ let hi = n - 1
17
+ while(pq.length > 0) {
18
+ let cur = pq.shift()
19
+ let idx = cur[1]
20
+ let val = cur[0]
21
+ if (A[hi] > val) {
22
+ res[idx] = A[hi--]
23
+ } else {
24
+ res[idx] = A[lo++]
25
26
27
+ return res
28
+}
0 commit comments