Count inversion algorithm in nlogn time complexity