Using Longest Increasing Subsequence || C++ Code  || Upper_bound
\nclass Solution {\n    int lengthOfLIS(vector<int>& nums) {\n        \n        int n = nums.size();\n        vector<int>seq;\n        seq.push_back(nums[0]);\n
```\nclass Solution {\n    int lengthOfLIS(vector<int>& nums) {\n        \n        int n = nums.size();\n        vector<int>seq;\n        seq.push_back(nums[0]);\n        \n        for(int i=1;i<n;i++){\n            if(seq.back() <= nums[i]){\n                seq.push_back(nums[i]);\n            }\n            else{\n                int ind = upper_bound(seq.begin(),seq.end(),nums[i]) - seq.begin();\n                seq[ind] = nums[i];\n            }\n        }\n        return seq.size();\n    }\npublic:\n    int kIncreasing(vector<int>& arr, int k) {\n        int ans = 0;\n        int n = arr.size();\n        for(int i=0;i<k;i++){\n            vector<int>temp;\n            for(int j=i;j<n;j+=k) {\n                temp.push_back(arr[j]);\n            }\n            int curr = lengthOfLIS(temp);\n            ans += (temp.size() - curr);\n        }\n        return ans;\n    }\n};\n```
['C', 'Binary Tree']