LIS | Binary-Search | TC - O(nlogn)
IDEA - For each group find the LIS. By finding LIS we will get the max len which has non-decreasing element, we can replace the remaing elements with elements o
**IDEA -** For each group find the LIS. By finding LIS we will get the max len which has non-decreasing element, we can replace the remaing elements with elements of LIS. we only need the count, so we subtract LIS length from the len of each group.\n\n```\nclass Solution {\npublic:\n    int kIncreasing(vector<int>& arr, int k) {\n        \n        int res = 0;\n        for(int i = 0; i < arr.size(); ++i) {\n            \n            if(arr[i] == -1) continue;\n            int j = i, len = 0;\n            vector<int> temp;\n            while(j < arr.size()) {\n                \n                if(temp.size()) {\n                    \n                    if(arr[j] >= temp.back()) temp.push_back(arr[j]);\n                    else {\n                        int index = upper_bound(temp.begin(), temp.end(), arr[j]) - temp.begin();\n                        temp[index] = arr[j];\n                    }\n                }\n                else temp.push_back(arr[j]);\n                \n                ++len;\n                arr[j] = -1;\n                j += k;\n            }\n            \n            res += len - temp.size();\n        }\n        \n        return res;\n    }\n};\n```
['C', 'Binary Tree']