Find the number of events that can be arranged without any conflicts.
Events are given in an array of strings with the YYYYMMDD format and are processed in the first-come, first-served manner.
You can assume that there are even number of strings and every ith (0-indexed) event has its beginnig and end given at the 2ith and 2i+1th position in the input array.
The event times are considered as [startTime, endTime)
Eg:
["20190101", "20190104", "20190103", "20190106", "20190106", "20190107"] = 2
There are only 2 events out of the 3 that can be arranged. This is because the 2nd event ( "20190103", "20190106") conflicts with the first event ("20190101", "20190104").
["20190101", "20190104", "20200103", "20200106", "20190106", "20190107"] = 3
All 3 events can be arranged. This is because the 2nd event is of the year 2020 (not 2019) and so does not clash with any other event.
Edit: We CANNOT sort is what the interviewer told me since it has been explicitly mentioned that the events are handled in first-come, first-served basis. I myself had this idea of sorting it based on the start time of the events similar to how we do it in the general interval problems but he said I cannot sort it. Which is why I was confused as to how this would be solved other than O(n^2) brute force :|
Edit 2: The problem is similar to https://leetcode.com/problems/my-calendar-i/, except that the implementation required just 1 method that takes in the input String array and returns the count of the events that can be arranged. Thanks to @EdmizJay