xxxxxxxxxx
import scala.collection.mutable.PriorityQueue
object MinPairsFromMaxHeap {
def getMinimumPairs(maxHeap: PriorityQueue[(Int, Int)], threshold: Int): List[(Int, Int)] = {
var result = List[(Int, Int)]()
while (maxHeap.nonEmpty && maxHeap.head._1 < threshold) {
val (value, index) = maxHeap.dequeue()
result = result :+ (value, index)
}
result
}
def main(args: Array[String]): Unit = {
// Example max heap of pairs (value, index)
val maxHeap = PriorityQueue((10, 0), (8, 1), (7, 2), (6, 3), (5, 4))
val threshold = 8
val minimumPairs = getMinimumPairs(maxHeap, threshold)
println("Minimum pairs below the threshold:")
minimumPairs.foreach(pair => println(s"Value: ${pair._1}, Index: ${pair._2}"))
}
}
xxxxxxxxxx
import scala.collection.mutable.PriorityQueue
object MinPairsFromMaxHeap {
def getMinimumPairs(maxHeap: PriorityQueue[(Int, Int)], threshold: Int): List[(Int, Int)] = {
var result = List[(Int, Int)]()
while (maxHeap.nonEmpty && maxHeap.head._1 < threshold) {
val (value, index) = maxHeap.dequeue()
result = result :+ (value, index)
}
result
}
def main(args: Array[String]): Unit = {
// Example max heap of pairs (value, index)
val maxHeap = PriorityQueue((10, 0), (8, 1), (7, 2), (6, 3), (5, 4))
val threshold = 8
val minimumPairs = getMinimumPairs(maxHeap, threshold)
println("Minimum pairs below the threshold:")
minimumPairs.foreach(pair => println(s"Value: ${pair._1}, Index: ${pair._2}"))
}
}