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 2db0eac commit 244b485Copy full SHA for 244b485
1944-number-of-visible-people-in-a-queue.js
@@ -1,3 +1,29 @@
1
+/**
2
+ * @param {number[]} heights
3
+ * @return {number[]}
4
+ */
5
+const canSeePersonsCount = function(heights) {
6
+ const res = []
7
+ if(heights.length === 0) return res
8
+
9
+ const n = heights.length
10
+ const stk = []
11
+ for(let i = n - 1; i >= 0; i--) {
12
+ let del = 0
13
+ while(stk.length && heights[i] > heights[stk[stk.length - 1]]) {
14
+ stk.pop()
15
+ del++
16
+ }
17
+ res.push(del + (stk.length ? 1 : 0))
18
+ stk.push(i)
19
20
21
+ return res.reverse()
22
+};
23
24
+// another
25
26
27
/**
28
* @param {number[]} heights
29
* @return {number[]}
0 commit comments