I’ve successfully solved this problem (https://www.codechef.com/ZCOPRAC/problems/ZCO15002/). But I wanted to solve this problem using yet another method. I thought that a merge sort type approach can work for this problem as we did in inversion count. So I partition the array in two halves. Find variation count for each half and the final sorted array when merging. Then return the result. But it provides me a WA judgment. Can somebody point out where am I being mistaken? Check method solve3(). Link: https://pastebin.com/7FW876kA.