Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
isaiahliu committed Jan 15, 2025
1 parent 089f9bc commit 9e9bc79
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/main/kotlin/p30xx/Problem3066.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package p30xx

import util.expect
import java.util.*

fun main() {
class Solution {
fun minOperations(nums: IntArray, k: Int): Int {
val queue = PriorityQueue<Long>()

nums.forEach {
queue.add(it.toLong())
}

var result = 0

while (queue.peek() < k) {
val n1 = queue.poll()
val n2 = queue.poll() ?: break

queue.add(n1 * 2 + n2)
result++
}


return result
}
}
expect {
Solution().minOperations(
intArrayOf(1), 1
)
}
}

0 comments on commit 9e9bc79

Please sign in to comment.