Implement a program that can enroll, unenroll, and waitlist students in online courses.
You may make either a command-line application (CLI) that accepts a text
file as input, or a web application that accepts GET
and POST
requests.
If developing a CLI, the text file will consist of input commands (one per line)
with space-delimited arguments. The CLI program must accept input from a text
file. For example, on Linux or OSX ./myprogram input.txt
should work.
If producing a web application, all REST URLs will have arguments as query strings or URL parameters.
The application must respond to the following commands:
- CLI:
AddCourse [key] [limit]
- REST:
POST /courses?key=foo&limit=5
This should create a new online course with a unique key
, e.g. cs101
, and
a seat limit
. The limit
annotates the maximum number of students that can
enroll in a course.
- CLI:
AddStudent [id] [limit]
- REST:
POST /students?id=bar&limit=3
This should create a student record with a unique id
and a course limit
.
The limit
annotates the maximum number of courses that the student may enroll
and waitlist in, e.g. a student with a limit of 3
can enroll in 2
courses
and get waitlisted in 1
. Additional enroll attempts will not enroll or
waitlist the student.
- CLI:
Enroll [student_id] [course_key]
- REST:
POST /students/:student_id/enroll?course_key=baz
This should enroll a student into a course, if the course has remaining seats and the student has not reached their course enrollment limit. A student may enroll in a course only once, and occupies one "seat."
If an attempt is made to enroll a student into a course that is full, e.g. the
course has a number of unique students enrolled that equal the limit
, then the
student is added to the course's waitlist.
If an attempt is made to enroll a student into a course when the student's course limit is reached, then the request is ignored.
In a web context, you have freedom to decide what response status codes are given for error states.
- CLI:
Drop [student_id] [course_key]
- REST:
POST /students/:student_id/drop?course_key=baz
This should remove a student from a course. The first student to have been waitlisted in the course (if there is a waitlist) should then be automatically enrolled into the course.
In a web context, you have freedom to decide what response status codes are given for error states.
- CLI:
List Students
(all text inputs will end with this) - REST:
GET /students
This should return (print to STDOUT
or as a response body) the following
plain text format:
[student_id]:
[course_key]: [status]
[course_key]: [status]
[student_id]:
[course_key]: [status]
[course_key]: [status]
-
All input will be syntactically valid; there's no need to check for illegal characters or malformed commands.
-
Input may not be semantically valid, e.g. we may try to enroll a student who has not yet been added. The CLI should ignore the input (no action), but the web application should return the appropriate status code.
-
Output order does not matter. (If it helps, we'll actually parse it as YAML.)
-
You do not use a database or filesystem persistence; the CLI app should be stateless, and the web server should reset state when restarted.
-
For the web application, response bodies other than the
GET
endpoint will not be read (only status codes). -
You are absolutely encouraged to use Internet searches or documentation. We ask, however, that you cite sources by URL for any code that is copied/adapted.
input.txt
AddCourse cs101 2
AddCourse nd001 1
AddCourse nd200 3
AddStudent lisa1 3
AddStudent bart2 2
AddStudent hom3r 1
Enroll hom3r cs101
Enroll lisa1 cs101
Enroll bart2 cs101
Enroll hom3r nd001
Enroll lisa1 nd001
Enroll bart2 nd001
Drop hom3r cs101
Enroll hom3r nd200
List Students
HTTP
POST /courses?key=cs101&limit=2
POST /courses?key=nd001&limit=1
POST /courses?key=nd200&limit=3
POST /students?id=lisa1&limit=3
POST /students?id=bart2&limit=2
POST /students?id=hom3r&limit=1
POST /students/hom3r/enroll?course_key=cs101
POST /students/lisa1/enroll?course_key=cs101
POST /students/bart2/enroll?course_key=cs101
POST /students/hom3r/enroll?course_key=nd001
POST /students/lisa1/enroll?course_key=nd001
POST /students/bart2/enroll?course_key=nd001
POST /students/hom3r/drop?course_key=cs101
POST /students/hom3r/enroll?course_key=nd200
GET /students
lisa1:
cs101: Enrolled
nd001: Enrolled
bart2:
cs101: Enrolled
nd001: Waitlisted
hom3r:
nd200: Enrolled
You may use any programming language you like, but keep in mind that we may ask you to explain or extend your code in follow-on interviews. We kindly ask that you limit your work to no more than 2 hours. We don't expect everyone to finish, but we ask that candidates prioritize (in order) the following:
-
Your program should output or respond with results.
-
Your program should have some automated tests.
-
You should include a
README.md
file with instructions on how to run code and tests, including how to install any dependencies your code may have. You should also include a brief description of your architecture and design choices. -
Adding students and courses.
-
Enrolling students into courses.
-
Respecting student course limits.
-
Respecting course seat limits by waitlisting students.
-
Dropping courses and dynamically-adjusting waitlists.
-
Semantic validations.
NOTE: We strongly discourage building a front-end or GUI. It's simply not a priority, and no one who has done so has "passed" this assessment. You have been forewarned: here be dragons!
Please email a zipped or tarballed package of your code, and omit identifying information (including source control, i.e. Git).