Created
May 21, 2024 05:51
-
-
Save SuryaPratapK/204762876a9f31a707e1e949260914d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int kIncreasing(vector<int>& arr, int k) { | |
int lisLen=0; | |
int n=arr.size(); | |
//LIS for K independent subarrays | |
for(int i=0;i<k;++i){ | |
vector<int> lis; | |
for(int j=i;j<n;j+=k){ | |
if(lis.empty() or lis.back()<=arr[j]) | |
lis.push_back(arr[j]); | |
else{ | |
int ub = upper_bound(lis.begin(),lis.end(),arr[j])-lis.begin(); | |
lis[ub] = arr[j]; | |
} | |
} | |
lisLen += lis.size(); | |
} | |
return arr.size()-lisLen; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment