-
Notifications
You must be signed in to change notification settings - Fork 0
/
DestroyShips.kt
49 lines (38 loc) · 1.18 KB
/
DestroyShips.kt
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
38
39
40
41
42
43
44
45
46
47
48
49
class DestroyShips {
companion object {
@JvmStatic
fun main(args: Array<String>) {
val sizeOfList = Integer.valueOf(readLine())
val listOfLoot = ArrayList<Int>()
readLine()?.let { line ->
line.split(" ").map {
it.toInt()
}.forEach {
listOfLoot.add(it)
}
}
println(getNumberOfDaysAfterDestructionStops(listOfLoot))
}
fun getNumberOfDaysAfterDestructionStops(lootArray: ArrayList<Int>): Int {
var days = 0
while (true) {
var elementRemoved = false
for (i in lootArray.size - 1 downTo 1) {
if (lootArray.get(i) > lootArray.get(i - 1)) {
lootArray.removeAt(i)
elementRemoved = true
}
}
if (elementRemoved) days++
else break
}
return days
}
}
}
/*
val array = arrayListOf(7, 6, 5, 8, 4, 7, 10, 9)
val array2 = arrayListOf(3, 6, 2, 7, 5)
al array3 = arrayListOf(0, -1, 1, 0, -4)
*
* */