All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g1801_1900.s1845_seat_reservation_manager.SeatManager.kt Maven / Gradle / Ivy

There is a newer version: 1.30
Show newest version
package g1801_1900.s1845_seat_reservation_manager

// #Medium #Design #Heap_Priority_Queue #Programming_Skills_II_Day_17
// #2023_06_22_Time_834_ms_(100.00%)_Space_94.6_MB_(91.67%)

import java.util.PriorityQueue
import java.util.Queue

@Suppress("UNUSED_PARAMETER")
class SeatManager(n: Int) {
    private val seats: Queue
    private var smallest: Int

    init {
        seats = PriorityQueue()
        smallest = 0
    }

    fun reserve(): Int {
        return if (seats.isEmpty()) ++smallest else seats.poll()
    }

    fun unreserve(seatNumber: Int) {
        seats.offer(seatNumber)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy