From c3aa058a1a3eac48e1821b194571e1d51921e76e Mon Sep 17 00:00:00 2001 From: Derek <109226053+derekjtong@users.noreply.github.com> Date: Thu, 18 May 2023 17:43:44 -0400 Subject: [PATCH] Create 1700-number-of-students-unable-to-eat-lunch.cpp --- ...number-of-students-unable-to-eat-lunch.cpp | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 cpp/1700-number-of-students-unable-to-eat-lunch.cpp 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(); + } +};