Question

Cafeteria Queue Lunchtime is the most awaited time of the day for students in your 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:

• cafeteriaQueue([100,80,90]) == 1

• cafeteriaQueue([100,120,30,50]) == 0

• cafeteriaQueue([100,90,30,25]) == 4

Answer #1

**Code for above
program in python :-** if u need code in any other
language leave a comment and do give a thumbs up.

```
# function to calculate Number of students who do not need to change position
def cafeteriaQueue(queue):
# creating a copy of the queue
sortedqueue = queue.copy()
# sorting the copied queue in descending order
sortedqueue.sort(reverse=True)
# initialising variable to keep sum of students who do not change position
student = 0
# iterating over both the lists
for i in range(len(queue)):
# checking if the position is same as earlier or not in the queue
if queue[i] == sortedqueue[i]:
# incrementing count
student+=1
return student
print(cafeteriaQueue([100,80,90]))
print(cafeteriaQueue([100,120,30,50]))
print(cafeteriaQueue([100,90,30,25]))
```

**Screenshot for reference :-**

MATHEMATICS
1. The measure of location which is the most likely to
be
influenced by extreme values in the data set is the a. range
b.
median c. mode d. mean
2. If two events are independent, then a. they must be
mutually
exclusive b. the sum of their probabilities must be equal to one
c.
their intersection must be zero d. None of these alternatives
is
correct. any value between 0 to 1
3. Two events, A and B,...

1. What are the requirements for successful price
discrimination? Does this type of dry cleaning qualify?
2. What are other examples of price discrimination?
3. The effectiveness of price discrimination is a different
question than whether businesses should be able to discriminate by
price. Is this an issue that deserves regulation, or is it best
left to the market?
Why Women Pay More
From dry cleaning to haircuts, women often pay more than
men due to gender pricing. Find out...

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 8 minutes ago

asked 27 minutes ago

asked 36 minutes ago

asked 55 minutes ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago