| Total Complexity | 5 |
| Complexity/F | 5 |
| Lines of Code | 22 |
| Function Count | 1 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | const Stack = require('../index') |
||
| 2 | const NGE = (arr) => { |
||
| 3 | let stack = new Stack(), |
||
| 4 | result = {} |
||
| 5 | for (let n of arr) { |
||
| 6 | if (stack.isEmpty() || n < stack.top()) { |
||
| 7 | stack.push(n) |
||
| 8 | continue |
||
| 9 | } |
||
| 10 | while (!stack.isEmpty() && n >= stack.top()) { |
||
| 11 | let p = stack.pop() |
||
| 12 | result[p] = n |
||
| 13 | } |
||
| 14 | stack.push(n) |
||
| 15 | } |
||
| 16 | |||
| 17 | while (!stack.isEmpty()) { |
||
| 18 | result[stack.pop()] = -1 |
||
| 19 | } |
||
| 20 | return result |
||
| 21 | } |
||
| 22 | module.exports = NGE; |