|
1 | 1 | # [1700.Number of Students Unable to Eat Lunch][title]
|
2 | 2 |
|
3 |
| -> [!WARNING|style:flat] |
4 |
| -> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm) |
5 |
| -
|
6 | 3 | ## Description
|
| 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 | + |
| 6 | +The number of sandwiches in the cafeteria is equal to the number of students. The sandwiches are placed in a **stack**. At each step: |
| 7 | + |
| 8 | +- 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. |
| 9 | +- Otherwise, they will **leave it** and go to the queue's end. |
| 10 | + |
| 11 | +This continues until none of the queue students want to take the top sandwich and are thus unable to eat. |
| 12 | + |
| 13 | +You are given two integer arrays `students` and `sandwiches` where `sandwiches[i]` is the type of the i<sup>th</sup> sandwich in the stack (`i = 0` is the top of the stack) and `students[j]` is the preference of the j<sup>th</sup> student in the initial queue (`j = 0` is the front of the queue). Return the number of students that are unable to eat. |
7 | 14 |
|
8 | 15 | **Example 1:**
|
9 | 16 |
|
10 | 17 | ```
|
11 |
| -Input: a = "11", b = "1" |
12 |
| -Output: "100" |
| 18 | +Input: students = [1,1,0,0], sandwiches = [0,1,0,1] |
| 19 | +Output: 0 |
| 20 | +Explanation: |
| 21 | +- Front student leaves the top sandwich and returns to the end of the line making students = [1,0,0,1]. |
| 22 | +- Front student leaves the top sandwich and returns to the end of the line making students = [0,0,1,1]. |
| 23 | +- Front student takes the top sandwich and leaves the line making students = [0,1,1] and sandwiches = [1,0,1]. |
| 24 | +- Front student leaves the top sandwich and returns to the end of the line making students = [1,1,0]. |
| 25 | +- Front student takes the top sandwich and leaves the line making students = [1,0] and sandwiches = [0,1]. |
| 26 | +- Front student leaves the top sandwich and returns to the end of the line making students = [0,1]. |
| 27 | +- Front student takes the top sandwich and leaves the line making students = [1] and sandwiches = [1]. |
| 28 | +- Front student takes the top sandwich and leaves the line making students = [] and sandwiches = []. |
| 29 | +Hence all students are able to eat. |
13 | 30 | ```
|
14 | 31 |
|
15 |
| -## 题意 |
16 |
| -> ... |
17 |
| -
|
18 |
| -## 题解 |
| 32 | +**Example 2:** |
19 | 33 |
|
20 |
| -### 思路1 |
21 |
| -> ... |
22 |
| -Number of Students Unable to Eat Lunch |
23 |
| -```go |
24 | 34 | ```
|
25 |
| - |
| 35 | +Input: students = [1,1,1,0,0,1], sandwiches = [1,0,0,0,1,1] |
| 36 | +Output: 3 |
| 37 | +``` |
26 | 38 |
|
27 | 39 | ## 结语
|
28 | 40 |
|
|
0 commit comments