We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2cf8781 commit f59a988Copy full SHA for f59a988
1700-number-of-students-unable-to-eat-lunch.js
@@ -0,0 +1,35 @@
1
+/**
2
+ * @param {number[]} students
3
+ * @param {number[]} sandwiches
4
+ * @return {number}
5
+ */
6
+const countStudents = function(students, sandwiches) {
7
+ const n = students.length
8
+ let res = n
9
+ while(helper(students, sandwiches)) {
10
+ const len = students.length
11
+ for(let i = 0; i < len; i++) {
12
+ if (students[0] === sandwiches[0]) {
13
+ students.shift()
14
+ sandwiches.shift()
15
+ res--
16
+ } else {
17
+ const tmp = students[0]
18
19
+ students.push(tmp)
20
+ }
21
22
23
+ return res
24
+};
25
+
26
+function helper(stu, san) {
27
+ const n = stu.length
28
+ let res = false
29
+ for(let i = 0; i < n; i++) {
30
+ if (stu[i] === san[0]) {
31
+ return true
32
33
34
35
+}
0 commit comments