Case Study 1
1. Countdown waiting time for John starts when the doctor begins seeing the rst
patient in the queue because the waiting time depends on the doctor's consultation
time and the number of patients ahead of John.
2. a. If Peter has already been in the consultation room for 2 minutes and the average
consultation time is 3 minutes, then he has 1 minute left. If there are 5 patients ahead
of John, then the estimated waiting time is (5 x 3) - 2 = 13 minutes. This is calculated
by multiplying the number of patients by the average time for each patient and
subtracting the time that has already passed.
b. If Peter has already in the consultation room when John arrived, and Peter’s
consultation takes 5 minutes, then John's estimated waiting time is (5 x 3) - 5 = 10
minutes.
Case Study 2
1. If John is the 11th patient in the queue and there are 10 patients ahead of him, we can
calculate the consultation time based on the assumption that there are two doctors, A
and B. Assuming that Doctor A has an average consultation time of 3 minutes per
patient and Doctor B has an average consultation time of 4 minutes per patient, we
can calculate the total consultation time as follows: (5 patients x 3 minutes) + (5
patients x 4 minutes) = 35 minutes. Since all patients have no speci c preference as
to which doctor they want to consult, 5 patients will be assigned to each doctor.
Therefore, if there are no other factors that can impact the consultation time, John’s
estimated waiting time when Doctor A and Doctor B started the consultation is 35
minutes.
2. Lucas has a consultation scheduled with Doctor B in 2 minutes. On average, Doctor
B's consultation time is 4 minutes. As a result, Lucas has 2 minutes left. Doctor A is
currently not seeing any patients. However, we can assume that Doctor A can start
seeing the rst patient while Doctor B is already seeing the rst patient. If all patients
have no preferences, we can divide 10 patients into 5 patients each for both doctors,
excluding John.
1. The estimated time for Doctor B to see 5 patients is (5 patients x 4 minutes) - 2
minutes (for Lucas) = 18 minutes.
2. The estimated time for Doctor A to see 5 patients is (5 patients x 3 minutes) = 15
minutes. Therefore, the estimated waiting time for John is 33 minutes.
Calculate patient waiting time
fi
fi
fi
fi
data class Doctor(val name: String, val consultationTime: Int)
fun calculatePatientWaitingTime(doctors: Array<Doctor>, patientPosition: Int): Int {
val totalConsultationTime = doctors.sumBy { it.consultationTime }
val averageConsultationTimePerDoctor = totalConsultationTime / doctors.size
// Calculate total waiting time for all patients ahead of the given position
val totalWaitingTime = averageConsultationTimePerDoctor * patientPosition
return totalWaitingTime
}