Sleep Sort is a sorting method described below:
let A = array to be sorted
let q = thread-safe queue
for each v in A :
create a new thread executing :
sleep(v seconds)
q.push(v)
DK's computer is extremely high-tech so that
1. the time of sleeping is absolutely accurate.
2. only the push operation (q.push(v)) and sleep operation executed non-instantly.
3. threads scheduling does not affect this sorting.
DK's magic thread-safe queue has to work on the q.push(v) operation for exact ceil(sqrt(v)) seconds.
During this time other thread which intends to use the queue has to wait for it until it finishes, and then take control of the queue.
When a thread finishes pushing and there are multiple threads waiting, the next one is chosen randomly, which may bring a wrong result.
Given an array A, check whether DK's Sleep Sort may cause a wrong result.