The school cafeteria offers circular and square sandwiches at lunch break, referred to by numbers 0 and 1 respectively. All students stand in a queue. Each student either prefers square or circular sandwiches. The number of sandwiches in the cafeteria is equal to the number of students. You are given two integer arrays students and sandwiches where sandwiches[i] is the type of the ith sandwich in the stack (i = 0 is the top of the stack) and students[j] is the preference of the jth student in the initial queue (j = 0 is the front of the queue). Part 1: Modify the code given and make it more efficient. You can try to implement your own stack or your own Queue. Or you can use the sandwiches array as a stack without making a separate Stack class. Same with the students array. Part 2: After modifying the code, explain how it works, and why it is more efficient than the solution that you started with. (Or, if it turns out that the change you made is not more efficient, try to explain why that might be).
The school cafeteria offers circular and square sandwiches at lunch break, referred to by numbers 0 and 1 respectively. All students stand in a queue. Each student either prefers square or circular sandwiches. The number of sandwiches in the cafeteria is equal to the number of students. You are given two integer arrays students and sandwiches where sandwiches[i] is the type of the ith sandwich in the stack (i = 0 is the top of the stack) and students[j] is the preference of the jth student in the initial queue (j = 0 is the front of the queue).
Part 1: Modify the code given and make it more efficient. You can try to implement your own stack or your own Queue. Or you can use the sandwiches array as a stack without making a separate Stack class. Same with the students array.
Part 2: After modifying the code, explain how it works, and why it is more efficient than the solution that you started with. (Or, if it turns out that the change you made is not more efficient, try to explain why that might be).
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 2 images