URL: https://leetcode.com/problems/minimum-number-of-operations-to-make-elements-in-array-distinct/ Signed-off-by: Matej Focko <me@mfocko.xyz>
15 lines
413 B
Kotlin
15 lines
413 B
Kotlin
class Solution {
|
|
fun minimumOperations(nums: IntArray): Int =
|
|
BooleanArray(101).let { seen ->
|
|
for (num in nums.withIndex().reversed()) {
|
|
when (seen[num.value]) {
|
|
true -> {
|
|
return num.index / 3 + 1
|
|
}
|
|
else -> seen[num.value] = true
|
|
}
|
|
}
|
|
|
|
0
|
|
}
|
|
}
|