1700. Number of Students Unable to Eat Lunch Easy
1/**
2 * [1700] Number of Students Unable to Eat Lunch
3 *
4 * The school cafeteria offers circular and square sandwiches at lunch break, referred to by numbers 0 and 1 respectively. All students stand in a queue. Each student either prefers square or circular sandwiches.
5 * The number of sandwiches in the cafeteria is equal to the number of students. The sandwiches are placed in a stack. At each step:
6 *
7 * If the student at the front of the queue prefers the sandwich on the top of the stack, they will take it and leave the queue.
8 * Otherwise, they will leave it and go to the queue's end.
9 *
10 * This continues until none of the queue students want to take the top sandwich and are thus unable to eat.
11 * You are given two integer arrays students and sandwiches where sandwiches[i] is the type of the i^th sandwich in the stack (i = 0 is the top of the stack) and students[j] is the preference of the j^th student in the initial queue (j = 0 is the front of the queue). Return the number of students that are unable to eat.
12 *
13 * Example 1:
14 *
15 * Input: students = [1,1,0,0], sandwiches = [0,1,0,1]
16 * Output: 0
17 * Explanation:
18 * - Front student leaves the top sandwich and returns to the end of the line making students = [1,0,0,1].
19 * - Front student leaves the top sandwich and returns to the end of the line making students = [0,0,1,1].
20 * - Front student takes the top sandwich and leaves the line making students = [0,1,1] and sandwiches = [1,0,1].
21 * - Front student leaves the top sandwich and returns to the end of the line making students = [1,1,0].
22 * - Front student takes the top sandwich and leaves the line making students = [1,0] and sandwiches = [0,1].
23 * - Front student leaves the top sandwich and returns to the end of the line making students = [0,1].
24 * - Front student takes the top sandwich and leaves the line making students = [1] and sandwiches = [1].
25 * - Front student takes the top sandwich and leaves the line making students = [] and sandwiches = [].
26 * Hence all students are able to eat.
27 *
28 * Example 2:
29 *
30 * Input: students = [1,1,1,0,0,1], sandwiches = [1,0,0,0,1,1]
31 * Output: 3
32 *
33 *
34 * Constraints:
35 *
36 * 1 <= students.length, sandwiches.length <= 100
37 * students.length == sandwiches.length
38 * sandwiches[i] is 0 or 1.
39 * students[i] is 0 or 1.
40 *
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/number-of-students-unable-to-eat-lunch/
45// discuss: https://leetcode.com/problems/number-of-students-unable-to-eat-lunch/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50 pub fn count_students(students: Vec<i32>, sandwiches: Vec<i32>) -> i32 {
51 0
52 }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn test_1700() {
63 }
64}
65
Back
© 2025 bowen.ge All Rights Reserved.