diff --git a/cpp/1700-number-of-students-unable-to-eat-lunch.cpp b/cpp/1700-number-of-students-unable-to-eat-lunch.cpp new file mode 100644 index 000000000..0f2097b38 --- /dev/null +++ b/cpp/1700-number-of-students-unable-to-eat-lunch.cpp @@ -0,0 +1,24 @@ +class Solution { +public: + int countStudents(vector& students, vector& sandwiches) { + queue q1; + for(int i = 0; i < students.size(); i++) { + q1.push(students[i]); + } + + int sandwichPos = 0; + int curr = 0; + while(!q1.empty() && curr <= q1.size()) { + if(q1.front() == sandwiches[sandwichPos]) { + q1.pop(); + sandwichPos++; + curr = 0; + } else { + q1.push(q1.front()); + q1.pop(); + } + curr++; + } + return q1.size(); + } +};