Plz correct this code
hello @devwrath1999
this is creating issue , this always return same element because a is same .
u need to change the range of ur search to make it correct.
ur updated code->
class Solution {
public:
vector<int> pancakeSort(vector<int> &a) {
//Complete this function
int n=a.size();
vector<int>p=a,k;
sort(p.begin(),p.end());
while(a!=p and n){
int m=*max_element(a.begin(),a.begin()+n);//updated
int id=find(a.begin(),a.end(),m)-a.begin();
reverse(a.begin(),a.begin()+id+1);
reverse(a.begin(),a.begin()+n);
k.push_back(id+1);
k.push_back(n);
n--;
}
return k;
}
};
try to submit it on leetcode
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.