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 d413c53 commit cc45ae0Copy full SHA for cc45ae0
855-exam-room.js
@@ -0,0 +1,35 @@
1
+/**
2
+ * @param {number} n
3
+ */
4
+const ExamRoom = function(n) {
5
+ let a = [];
6
+ return { seat, leave }
7
+ function seat() {
8
+ if (a.length == 0) {
9
+ a.push(0);
10
+ return 0;
11
+ }
12
+ let dis = Math.max(a[0], n - 1 - a[a.length - 1]);
13
+ for (let i = 1; i < a.length; i++) dis = Math.max(dis, a[i] - a[i - 1] >> 1);
14
+ if (a[0] == dis) {
15
+ a.unshift(0);
16
17
18
+ for (let i = 1; i < a.length; i++) {
19
+ if (a[i] - a[i - 1] >> 1 == dis) {
20
+ a.splice(i, 0, a[i] + a[i - 1] >> 1);
21
+ return a[i];
22
23
24
+ a.push(n - 1);
25
+ return n - 1;
26
27
+ function leave(p) {
28
+ for (let i = 0; i < a.length; i++) {
29
+ if (a[i] == p) {
30
+ a.splice(i, 1);
31
+ break;
32
33
34
35
+};
0 commit comments