Skip to content

Commit 987a0aa

Browse files
authored
Merge pull request #2489 from derekjtong/Create-1700-number-of-students-unable-to-eat-lunch.cpp
Create 1700-number-of-students-unable-to-eat-lunch.cpp
2 parents b0e1a66 + c3aa058 commit 987a0aa

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Diff for: cpp/1700-number-of-students-unable-to-eat-lunch.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
public:
3+
int countStudents(vector<int>& students, vector<int>& sandwiches) {
4+
queue<int> q1;
5+
for(int i = 0; i < students.size(); i++) {
6+
q1.push(students[i]);
7+
}
8+
9+
int sandwichPos = 0;
10+
int curr = 0;
11+
while(!q1.empty() && curr <= q1.size()) {
12+
if(q1.front() == sandwiches[sandwichPos]) {
13+
q1.pop();
14+
sandwichPos++;
15+
curr = 0;
16+
} else {
17+
q1.push(q1.front());
18+
q1.pop();
19+
}
20+
curr++;
21+
}
22+
return q1.size();
23+
}
24+
};

0 commit comments

Comments
 (0)