You are viewing a single comment's thread. Return to all comments →
My code passes all test cases except for test cases 19 and 23. It gives timeout for those 2 cases. Please suggest an optimized solution.
long n, temp; vector<long> v; cin >> n; for(long i=0; i<n; i++){ cin >> temp; v.push_back(temp); } int die_count=1, days=0; while(die_count>0){ die_count = 0; for(long i=v.size()-1; i>0; i--){ if(v[i] > v[i-1]){ v.erase(v.begin()+i); die_count++; } } if(die_count>0) days++; } cout << days << endl;
Seems like cookies are disabled on this browser, please enable them to open this website
Poisonous Plants
You are viewing a single comment's thread. Return to all comments →
My code passes all test cases except for test cases 19 and 23. It gives timeout for those 2 cases. Please suggest an optimized solution.