// O(n) Linear search
void MinMaxValue(vector<int>arr) {
int mini = arr[0], maxi = arr[0];
for(int i=1;i<arr.size();i++) {
if(arr[i]<mini)
mini = arr[i];
if(arr[i]>maxi)
maxi = arr[i];
}
cout<<mini<<" "<<maxi;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter