I was asked this question in my interview. I know that on StackOverflow, we are not supposed to ask for direct answers for the i/w questions. So instead of that, I would to ask for correct approach/hint to solve it
I have been given two array of movie starts times and end times.
int start[], int end[]
For these two arrays, I have to find the max movies I can watch. In my opinion, this is the exact opposite of the problem, where we have to find the max overlap for given intervals.
My approach was this, if for any movie, there is no overlap, we should watch it. However, if there is a overlap and the other overlap is of shorter duration then discard this movie else take this movie.
This algorithm fails this dataset
movie 1:4,8 movie 2 :6,11 movie 3:2,5
This algorithms correctly eliminates 4,8 as 2,5 is more desirable. However, it eliminates 6,11 in favor of 4,8 even though that is something we have already eliminated and it should be considered.
May I know what is the correct approach to solve this problem?