That depends what exactly you mean by "constant sized". The time to find the minimum of a list with 917,340 elements is with a very large constant factor. The time to find the minimum of various lists of different constant sizes is and likely where is the size of each list. Finding the minimum of a list of 917,340 elements takes much longer than finding the minimum of a list of 3 elements.

Answer from gnasher729 on Stack Exchange
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-list-max-method
Python List max() Method - GeeksforGeeks
July 23, 2025 - Return Type: It return the maximum value present in the list. Lets look at some examples to find max element in Python list:
Discussions

performance - How efficient is Python's max function - Stack Overflow
If you want to maximize based on ... the time complexity of "someFunc." ... But yes for normal case it should just iterate over the list and find the max using normal compare function. ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. 475 What do I use for a max-heap implementation in Python... More on stackoverflow.com
🌐 stackoverflow.com
algorithm - Big O of min and max in Python - Stack Overflow
It's O(n). It's a general algorithm, you can't find the max/min in the general case without checking all of them. Python doesn't even have a built-in sorted collection type that would make the check easy to specialize. A for loop would have the same algorithmic complexity, but would run slower ... More on stackoverflow.com
🌐 stackoverflow.com
How to Compute Max Value with Linear Time Complexity When 'k' Is Not Fixed?
On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge. If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options: Limiting your involvement with Reddit, or Temporarily refraining from using Reddit Cancelling your subscription of Reddit Premium as a way to voice your protest. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/learnprogramming
4
0
January 28, 2024
how to find maximum from a list using a for loop in pythonic way?
but I want to use a syntax like this: var = max(item) for item in lst That doesn't look pythonic to me. In fact, it's not even right Python syntax. More on reddit.com
🌐 r/learnpython
55
5
June 27, 2023
🌐
Medium
medium.com › @lcao_5526 › 3-ways-to-find-the-largest-number-in-python-and-their-complexities-49f2a1e221ee
3 Ways to Find the Largest Number in Python and Their Complexities | by Lulu Cao | Medium
April 13, 2024 - In conclusion, the best solution to find the largest number in Python will be using a max() function, which has a time complexity of O(n) and a space complexity of O(1).
🌐
Python Pool
pythonpool.com › home › blog › using python max function like a pro | python max()
Using Python Max Function Like a Pro | Python max() - Python Pool
June 14, 2021 - ... The time complexity of the python max function is O(n). Unlike max functions in other programming languages like C++, it offers a variety of uses. We can apply it on the string, which ...
🌐
Python
wiki.python.org › moin › TimeComplexity
TimeComplexity - Python Wiki
Internally, a list is represented as an array; the largest costs come from growing beyond the current allocation size (because everything must move), or from inserting or deleting somewhere near the beginning (because everything after that must move).
Find elsewhere
🌐
Quora
quora.com › What-is-the-best-algorithm-for-finding-the-max-in-an-array-and-what-is-its-complexity
What is the best algorithm for finding the max in an array and what is its complexity? - Quora
Answer (1 of 7): As it needs traversal of all of the array. Without checking all of the elements, min|max can't be find out. So worst case is O(n) Best is constant time
🌐
Reddit
reddit.com › r/learnprogramming › how to compute max value with linear time complexity when 'k' is not fixed?
r/learnprogramming on Reddit: How to Compute Max Value with Linear Time Complexity When 'k' Is Not Fixed?
January 28, 2024 -

Body: Hello! I'm stuck on a problem and could really use some fresh perspectives. I'm trying to figure out a linear time solution (`Theta(n)`) for a problem that's a bit tricky due to its varying parameters.

Here's the Challenge: Picture a line of creatures, each with its own strength and a unique ability. We have two lists: `x` for their strengths and `k` for the number of creatures in front of each (including itself) they can turn to for help.

Example to Illustrate: Let's say `x = [5, 10, 7, 2, 20]` and `k = [1, 2, 1, 3, 2]`. We need to find the maximum strength each creature can muster. For the fourth creature, it looks at the 3 creatures (`k[3] = 3`) - itself and the two creatures before it, considers the strengths `[10, 7, 2]`, and realizes it can leverage a maximum strength of `10`.

Our goal is to output a list where each element is this maximum accessible strength for each creature.

Where I'm Stuck: Here's my Python attempt so far:

def calculate_ output(x, k):
    output = []
    for i in range(len(x)):
        start_index = max(0, i - k[i])
        end_index = i + 1
        output.append(max(x[start_index:end_index]))
    return output

This isn't efficient. The nested iterations due to `max` make it O(n^2). For each creature, we slice and dice through the list based on `k`, which isn't ideal.

Looking for Advice: I'm hitting a wall here. Maybe there's a way to do this with a sliding window, but the variable range in `k` throws a wrench in the works. Any thoughts on data structures or algorithms to make this linear?

Thanks in advance! Looking forward to your insights.

🌐
GitHub
gist.github.com › yvan-sraka › 52384523a92bb0910d770f0fdde59bbd
Max function implementation explained in Python · GitHub
if list[0] > rec_max(list[1:]): # Calling here once return list[0] else: ''' Calling here again, which will lead to recurse the function it already computed the value for. This will impact the time complexity of the function majorly for large lists. ''' return rec_max(list[1:]) Instead of that, we can write it as below ·
🌐
UCI
ics.uci.edu › ~pattis › ICS-33 › lectures › complexitypython.txt
Complexity of Python Operations
Implementation 2 adds the new value into the pq by scanning the list or linked list for the right spot to put it and putting it there, which is O(N). Lists store their highest priority at the rear (linked lists at the front); it removes the highest priority value from the rear for lists (or the front for linked lists), which is O(1). So Implementations 1 and 2 swap the complexity classes in their add/remove method. Implementation 1 doesn't keep the values in order: so easy to add but hard to find/remove the maximum (must scan).
🌐
Medium
medium.com › @khasnobis.sanjit890 › design-an-algorithm-that-can-return-the-maximum-item-of-a-stack-in-o-1-running-time-complexity-b312b9575d9c
Design an algorithm that can return the Maximum item of a stack in O(1) running time complexity. We can use O(N) extra memory! : Stack Again : Chapter 3 : In Python | by Sanjit Khasnobis | Medium
April 26, 2022 - We will build the stack from scratch ... the Maximum element of the Stack. So we are allowed to use O(N) extra memory but we have to fetch the item in constant Time complexity of O(1). If you are reading this article for first time you can refer to my earlier article on Stack in python as below ...
🌐
GeeksforGeeks
geeksforgeeks.org › python-program-to-find-largest-number-in-a-list
Python Program to Find Largest Number in a List - GeeksforGeeks
Python provides a built-in max() function that returns the largest item in a list or any iterable. The time complexity of this approach is O(n) as it traverses through all elements of an iterable.
Published   October 21, 2024
🌐
Reddit
reddit.com › r/learnpython › how to find maximum from a list using a for loop in pythonic way?
r/learnpython on Reddit: how to find maximum from a list using a for loop in pythonic way?
June 27, 2023 -

lst = [1,2,3,4,5]

basically, I want to find max: max(lst)

but I want to use a syntax like this: var = max(item) for item in lst

first, why does this return a generator object instead of throwing some error?

And second, how to do it properly?

Edit: so basically there is a function. I need to compute the max value returned by the function. The function should calculate values from a list of inputs.

So, I need to de this:

var = max(func(item)) for item in lst

I just wanted to know if we can do this in one or two liner?

🌐
Quora
quora.com › What-is-the-runtime-complexity-of-finding-the-maximum-value-in-an-array
What is the runtime complexity of finding the maximum value in an array? - Quora
But, if items aren’t sorted, you’ll mandatory have a complexity in O(n). It means that you’ll have mandatory to visit every item in your array to be sure to find them maximum value.
🌐
Quora
quora.com › Is-it-possible-to-find-the-maximum-element-in-an-array-with-the-time-complexity-less-than-O-n
Is it possible to find the maximum element in an array with the time complexity less than O(n)? - Quora
Answer (1 of 13): Hello Dear, Actually it's Tricky, Reason : Array is sequential Data Structure you must traverse all the element in order to derive maximum element among all. Approach : 1: The simplest way to get maximum among elements in array is to Store initial element of array in tempor...
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › functions › max.html
max — Python Reference (The Right Way) 0.1 documentation
Returns the largest item in an iterable or the largest of two or more arguments · max (collection[, key])
🌐
Reddit
reddit.com › r/algorithms › how to compute max value with linear time complexity when 'k' is not fixed?
r/algorithms on Reddit: How to Compute Max Value with Linear Time Complexity When 'k' Is Not Fixed?
January 28, 2024 -

Body: Hello! I'm stuck on a problem and could really use some fresh perspectives. I'm trying to figure out a linear time solution (`Theta(n)`) for a problem that's a bit tricky due to its varying parameters.

Here's the Challenge: Picture a line of creatures, each with its own strength and a unique ability. We have two lists: `x` for their strengths and `k` for the number of creatures in front of each (including itself) they can turn to for help.

Example to Illustrate: Let's say `x = [5, 10, 7, 2, 20]` and `k = [1, 2, 1, 3, 2]`. We need to find the maximum strength each creature can muster. For the fourth creature, it looks at the 3 creatures (`k[3] = 3`) - itself and the two creatures before it, considers the strengths `[10, 7, 2]`, and realizes it can leverage a maximum strength of `10`.

Our goal is to output a list where each element is this maximum accessible strength for each creature.

Where I'm Stuck: Here's my Python attempt so far:

def calculate_ output(x, k):
    output = []
    for i in range(len(x)):
        start_index = max(0, i - k[i])
        end_index = i + 1
        output.append(max(x[start_index:end_index]))
    return output

This isn't efficient. The nested iterations due to `max` make it O(n^2). For each creature, we slice and dice through the list based on `k`, which isn't ideal.

Looking for Advice: I'm hitting a wall here. Maybe there's a way to do this with a sliding window, but the variable range in `k` throws a wrench in the works. Any thoughts on data structures or algorithms to make this linear?

Thanks in advance! Looking forward to your insights.

🌐
GeeksforGeeks
geeksforgeeks.org › max-min-python
max() and min() in Python - GeeksforGeeks
June 17, 2021 - Syntax : max(a,b,c,..,key,default) Parameters : a,b,c,.. : similar type of data. key : key function where the iterables are passed and comparison is performed default : default value is passed if the given iterable is empty Return Value : Returns the maximum of all the arguments. Exceptions : Returns TypeError when conflicting types are compared. ... # Python code to demonstrate the working of # max() # printing the maximum of 4,12,43.3,19,100 print("Maximum of 4,12,43.3,19 and 100 is : ",end="") print (max( 4,12,43.3,19,100 ) )