-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbribes.js
More file actions
37 lines (35 loc) · 907 Bytes
/
bribes.js
File metadata and controls
37 lines (35 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// https://www.hackerrank.com/challenges/new-year-chaos/problem
function minimumBribes(q) {
// console.log('--->', q)
let subornos = []
for (let position = 0; position < q.length; position++) {
let bribs = 0
const pnumber = q[position]
console.log(pnumber, q[position + 1])
const actualPosition = position + 1
for (let y = actualPosition; y < q.length; y++) {
const nnumber = q[y]
if (pnumber > nnumber) {
bribs = bribs + 1
} else {
break
}
}
if (bribs > 0) {
subornos.push(bribs)
}
// console.log(pnumber, bribs)
}
let bribs = 0
let isChaotic = false
for (let x = 0; x < subornos.length; x++) {
bribs = bribs + subornos[x]
console.log(subornos[x])
if (subornos[x] >= 2) {
isChaotic
}
}
console.log(bribs)
if (isChaotic) console.log('Too chaotic')
}
minimumBribes([2, 5, 1, 3, 4])