I got the idea to solve ZCO15003 using the greedy method but I am finding it difficult to code in Java.
My method:
- Sort the 2d array based on closing interval.
- take the closing interval of the first element in array
- Iterate over the array checking if its fits in that interval and if it fits then remove it from array
- the final answer is the size of the array.
Any leads are appreciated.
Check out this link. Try to solve on your own for some time after reading the hints.
I can show you my code but it is in C++.
Why would the greedy approach not work?
Sorry, my bad.
I overlooked the “based on closing interval” part.
When I first solved the problem, I sorted the array on the basis of opening interval and got WA. I thought he had some similar and thus the comment.
I will edit my comment.