Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0b7a841

Browse files
committed
Add solution #1700
1 parent 1052461 commit 0b7a841

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,484 LeetCode solutions in JavaScript
1+
# 1,485 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1309,6 +1309,7 @@
13091309
1695|[Maximum Erasure Value](./solutions/1695-maximum-erasure-value.js)|Medium|
13101310
1696|[Jump Game VI](./solutions/1696-jump-game-vi.js)|Medium|
13111311
1697|[Checking Existence of Edge Length Limited Paths](./solutions/1697-checking-existence-of-edge-length-limited-paths.js)|Hard|
1312+
1700|[Number of Students Unable to Eat Lunch](./solutions/1700-number-of-students-unable-to-eat-lunch.js)|Easy|
13121313
1716|[Calculate Money in Leetcode Bank](./solutions/1716-calculate-money-in-leetcode-bank.js)|Easy|
13131314
1718|[Construct the Lexicographically Largest Valid Sequence](./solutions/1718-construct-the-lexicographically-largest-valid-sequence.js)|Medium|
13141315
1726|[Tuple with Same Product](./solutions/1726-tuple-with-same-product.js)|Medium|
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* 1700. Number of Students Unable to Eat Lunch
3+
* https://leetcode.com/problems/number-of-students-unable-to-eat-lunch/
4+
* Difficulty: Easy
5+
*
6+
* The school cafeteria offers circular and square sandwiches at lunch break, referred to by
7+
* numbers 0 and 1 respectively. All students stand in a queue. Each student either prefers
8+
* square or circular sandwiches.
9+
*
10+
* The number of sandwiches in the cafeteria is equal to the number of students. The sandwiches
11+
* are placed in a stack. At each step:
12+
* - If the student at the front of the queue prefers the sandwich on the top of the stack, they
13+
* will take it and leave the queue.
14+
* - Otherwise, they will leave it and go to the queue's end.
15+
*
16+
* This continues until none of the queue students want to take the top sandwich and are thus
17+
* unable to eat.
18+
*
19+
* You are given two integer arrays students and sandwiches where sandwiches[i] is the type of
20+
* the ith sandwich in the stack (i = 0 is the top of the stack) and students[j] is the
21+
* preference of the jth student in the initial queue (j = 0 is the front of the queue).
22+
* Return the number of students that are unable to eat.
23+
*/
24+
25+
/**
26+
* @param {number[]} students
27+
* @param {number[]} sandwiches
28+
* @return {number}
29+
*/
30+
var countStudents = function(students, sandwiches) {
31+
const preferenceCount = [0, 0];
32+
for (const pref of students) {
33+
preferenceCount[pref]++;
34+
}
35+
36+
for (const sandwich of sandwiches) {
37+
if (preferenceCount[sandwich] === 0) {
38+
return preferenceCount[0] + preferenceCount[1];
39+
}
40+
preferenceCount[sandwich]--;
41+
}
42+
43+
return 0;
44+
};

0 commit comments

Comments
 (0)