Number of Students Unable to Eat Lunch
EasyArrayStackQueueSimulation
Solution
export function countStudents(students: number[], sandwiches: number[]): number {
const n = students.length;
const counts = [0, 0];
students.forEach((student) => {
counts[student] += 1;
});
let i = 0;
while (i < n && 0 < counts[sandwiches[i]]) {
counts[sandwiches[i]] -= 1;
i += 1;
}
return n - i;
}