Question: We are given an array of 2n integers wherein each pair in this array of integers represents the year of birth and the year of death of a dinosaurs respectively. Th
Create a structure called DinosaurEvent
and have it store one year- the year when the event occurred and the type of event - birth or death. Implement your own compare function to pass to qsort to first sort according to year and than to event(take into consideration if the deaths happen before births or the other way around i.e. is the range inclusive in either end) Iterate over the array you are given and put all events in a vector. After that sort the vector and process events in turn. Process all events for a given year at the same time(or only births or death depending on the statement) and re-compute the current number of living dinosaurs(for birth increase by one for death decrease by one). Store the maximum value at all times and this will be your answer. Hope that makes sense.
Sorry for giving the whole solution by I could not figure out a way to give you a hint without actually saying it all.