Instead of having to update max every time you remove a student, you could just use students.size() directly where you need it.