C++| O(Nlog(N))
// If u observe carefully you will get to know that the problem is similar to LIS(Longest Increasing Subsequence) problem. In LIS we have only one set of data t
// If u observe carefully you will get to know that the problem is similar to LIS(Longest Increasing Subsequence) problem. In LIS we have only one set of data to find, but in this problem we have to find in k different set. If u dry run the test case u will find that all the set are independent to each other so we can treat all the set as seperate LIS.\nclass Solution {\npublic: \n\n    int kIncreasing(vector<int>& ar, int k) {\n        int ans=0,n=ar.size();\n        vector<int>lis;\n        for(int i=0;i<k;i++)\n        {\n            int s=0;\n            for(int j=i;j<n;j+=k)\n            {\n                auto it=upper_bound(lis.begin(),lis.end(),ar[j]);\n                if(it==lis.end())\n                    lis.push_back(ar[j]);\n                else *it=ar[j];\n                s++;\n            }\n            ans+=s-(int)lis.size();\n            lis.clear();\n        }\n        return ans;\n    }\n};
[]