[C++] Longest Non-Decreasing Subsequence technique. O(k*n*log(n))
This approach uses the upper bound function in C++.\n\nUpper Bound return an iterator to the next smallest greater number than a key in a sorted array.\nEg: if 
This approach uses the **upper bound** function in C++.\n\nUpper Bound return an iterator to the **next smallest greater number** than a **key** in a **sorted array**.\n*Eg: if sorted arr = [1, 2, 3, 4, 5], and key = 4, then **upper_bound(arr.begin, arr.end(), key)** would return an iterator to the **first occurance of element "5"***.\n\n1. So, we create **k subsequences of the original array**, and \n2. Find the ***Length of Longest Non-Decreasing Subsequence*** of each of those k subsequences using **Upper Bound**,  and therefore, \n3. The difference between len(**kth original** subsequence) and len(**kth longest** subsequence), gives us the number of operations required for that **kth** subsequence.\n\n***CODE*** :-\n```\nint kIncreasing(vector<int>& arr, int k) {\n        int ops = 0;\n        for(int i=0; i<k; i++) {\n            vector<int> v;\n            for(int j = i; j < arr.size(); j += k)\n                v.push_back(arr[j]);\n            ops += v.size() - lengthOfLNDS(v);\n        }\n        return ops;\n    }\n    \n    int lengthOfLNDS(vector<int> nums) {\n        vector<int> v = {nums[0]};\n        int index;\n        \n        for(int i=1; i < nums.size(); i++) {\n            index = upper_bound(v.begin(), v.end(), nums[i]) - v.begin();\n            if(index == v.size())\n                v.push_back(nums[i]);\n            else\n                v[index] = nums[i];\n        }\n        return v.size();\n    }\n```\n\nThnak you :). Please upvote.
['C', 'Binary Tree']