Although there is an explicit for loop solution for the same, I was looking for a solution to get the max in a vector in a given range.
E.g. let's say a vector has 3,5,7,9,5,1,6,7,4,2 and the given range is [4,8] then the max element should be 7.
I was looking for a one liner/short solution using some inbuilt std library functions for the same.
The array contains all positive numbers.
This is what I have tried :
int max = -1;
for (i = 0; i < n; i++)
if (arr[i] > max && arr[i] >= low && arr[i] <= high)
max = arr[i];
I am just looking for a simple standard library vector solution.