Using c++ stl we can get max and min in 0(1)


#1

just create a set(which internally is implemented as a tree) and get the max and min in 0(1)


#2

insertion in set takes log(n) time


#3

even c++STl’s “min” and “max” takes O(n) time because it traverses through the entire array.
We can only get min and max in O(1) time iff the given array is sorted otherwise it at least takes O(n) time…


#4

Seeking might take O(1) time but constructing the set itself will take O(NlogN) time .