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


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


insertion in set takes log(n) time


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…


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


This STL in your comment are implemented using binary trees and their execution takes O(NlogN) times. So, its never O(1).