Number of Students Unable to Eat Lunch LeetCode solution in C++

1
class Solution {
2
public:
3
int countStudents(vector<int> &students, vector<int> &sandwiches) {
4
int size = students.size();
5
queue<int> student_choice;
6
for (int i = 0; i < size; ++i) {
7
student_choice.push(students[i]);
8
}
9
int rotations = 0, i = 0;
10
while (student_choice.size() && rotations < student_choice.size()) {
11
if (student_choice.front() == sandwiches[i]) {
12
student_choice.pop();
13
i++;
14
rotations = 0;
15
} else {
16
int choice = student_choice.front();
17
student_choice.pop();
18
student_choice.push(choice);
19
rotations++;
20
}
21
}
22
return student_choice.size();
23
}
24
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0