Let P=max({ti:ci=0}∪{0}) and Q=min({ti:ci=1. We need P≤T<Q and T>0, equivalent to P<Q. Choose T=P if P>0, otherwise T=0.5 milliseconds. Time is O(N) and auxiliary space O(1). A naive solution sorts by time, checks that equal times have equal labels, and forbids a 0 after a 1. It passes in O(NlogN).
Solution written by GPT6