Currently I'm only aware of the following:
vector<int> nums= {3,2,1,0,2,3,3,1,0,0};
return max_element(nums.begin(), nums.end())-nums.begin();
But in that case it would return the lowest index of the maximum element.
A way around it would be:
vector<int> nums= {3,2,1,0,2,3,3,1,0,0};
int n = *max_element(nums.begin(), nums.end());
for(int i=nums.size()-1; i>-1; i--){
if(nums[i]==n) {
return i;
break;
}
}
But is there any simpler way that I can achieve the same result without bruteforcing it?