I have a linked list in Java ,say , LinkedList<T> list = new LinkedList<T>(); and I need to find the max / min element in it most efficiently , how can I do it?
How can I use Collections.max() function to find the max element from my linked list? What is the time complexity of this function ?
The time complexity is
O(n)if you want it to be lower e.g.O(1)you need to use a different data structure such as a TreeSet.