Loading...
Loading...
Each student has at most one mentor, and each mentor keeps a list of up to 3 students. Both sides must always agree.
Write Student (name, Teacher mentor) and Teacher (name, Student[3], count). Only Teacher.addStudent(Student s) and Teacher.removeStudent(Student s) change the link, and each sets both sides. A student who changes mentor leaves the old mentor's list first.
assign S T, drop S, who S or list T.ASSIGNED S TO T, ALREADY S T or T FULL; DROPPED S or S HAS NO MENTOR; S: T or S: NONE; T: S1 S2 … or T: -.Example
Input
2 Khan Rao 3 Diya Aarav Kavya 6 assign Diya Khan assign Aarav Khan assign Diya Rao list Khan who Diya list Rao
Output
ASSIGNED Diya TO Khan ASSIGNED Aarav TO Khan ASSIGNED Diya TO Rao Khan: Aarav Diya: Rao Rao: Diya
Diya moves from Khan to Rao: she leaves Khan's list and her mentor changes.
Try the problem first. Open one hint at a time.
addStudent stores the student, then calls s.setMentor(this); setMentor must not call back.
For a mentor change: check that the new mentor has room, then remove the student from the old mentor, then add.
removeStudent shifts the list left and sets the student's mentor to null.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor