Act like a computer

Cafeteria Queue

Lunchtime is the most awaited time of the day for students in you school. Not only because there are no classes, but because the lunch is really good! At 12, all students run to the cafeteria and queue up for the meal.

Professor Yilma noticed that and decided to use it to encourage students to do better in his course. He convinced the cafeteria people to serve the students not in the order they arrived, but in order of their grades, highest to lowest. This way, students with higher grades get their lunch first.

Your task is simple: given the arrival time of the students in the cafeteria, and their respective grades in the math class, reorder the queue according to the math grades, and check how many students do not need to change place in this reordering.

Implement the function cafeteriaQueue(Q) that takes as input a list of the students in the queue, identified by their grades. For example, if the first students that arrived has grade 100, the second has grade 80, and the third student's grade is 90, Q would be [100,80,90]. There will be no students with the same grade due to professor Yilma's fine grained scoring system. This function returns the number of students that do not need to change places in line.

For example:

assert(cafeteriaQueue([100,80,90]) == 1)
assert(cafeteriaQueue([100,120,30,50]) == 0)
assert(cafeteriaQueue([100,90,30,25]) == 4)

Kth Largest

Implement the function kthLargest(L, k) that returns the Kth largest element in the list L. If $k = 1$, the function returns the 1st largest element, if $k = 2$ the function returns the 2nd largest, and so on. You can assume $1 \leq k \leq len(L)$. For example:

kthLargest([1,5,1,1,0], 1) == 5
kthLargest([1,5,1,1,0], 2) == 1
kthLargest([1,5,1,1,0], 3) == 1
kthLargest([1,5,1,1,0], 5) == 0
kthLargest([42, 9, 15, 2022], 2) == 42