the hint says expects greedy solution…but how can greedy work??
i tried a recursive solution like backtracking but it gave tle
also, what is wrong with this approach??
for(int i=0; i<n; i++)
{
if(k<=0) break;
int maxidx = i;
for(int j=i+1; j<n; j++)
{
if(arr[j]>arr[maxidx])
maxidx = j;
}
if(maxidx!=i)
{
k--;
swap(arr[i], arr[maxidx]);
}
}
