I got this question, removing some details it can be described as below :
Given a list of each student's scores for the two exams, for example [60, 70], [70, 80]. As a TA you can pass or fail the students.
The restriction is, for any two students A, B, if A's exams are both better than B, they cannot both pass, only A can pass.
You still want to pass as many student as possible, what is the max students pass the course.
For example, you have [ [40, 90] , [50, 100], [60, 80]] , you can only have 2 students pass.
[40,90] is failed since 40<50 && 90 < 100. but [50, 100], [60, 80] can co-exists. since 50<60 but 100 > 80.
The bad news is I cannot really think of a pattern to solve this problem, I failed to match this problem to any data structure. For one time I thought this is a graph theory but it seems not.
Update: for a corner case like [20, 30], [21, 31], [22, 32], [23, 33] , only one student passed [23, 33].
I then followed this clarification do below :
a. sort by exam[0] to find the highest , say [60, 80], then any students whose exam[1] < 80 failed. The first sort gives me [ [40, 90] , [50, 100], [60, 80]].
b. I then sort by exam[1], say [50, 100], then any student whose exam[0] < 50 failed. Here remove [40, 90].
The final answer is the total number of students left after step a. + b.
However, this solution is greedy-based(?) I cannot think of a way to prove its correctness. The interviewer did not comment on the correctness, but sadly, he did ask.
Any advice is appreciated. Good luck to you!