this hiring test is now over so link of problem is not available.

Can anyone tell the approach better than nlogn as sorting array gives TLE

1 Like

First of all, weird that an \mathcal{O}(n\log n) algorithm doesn’t get accepted. Based on your final comment I think you understand the most important piece of the algorithm. To make it \mathcal{O}(n) use counting sort. Further improvements with regard to complexity can’t be made because reading in input is already \mathcal{O}(n)