Yeah min() is O(n). But the problem's test cases are not strict enough to expose the inefficient algorithm. Python also adds another dimension because its builtin methods are often a lot faster than what you could write in pure python. I think that makes it easier to get away with a suboptimal algorithm. Answer from aocregacc on reddit.com
Discussions

Python: Time complexity of min() function inside for loop - Stack Overflow
I'm calculating time complexities of algorithms and I assumed both code below to have time complexities of O(n^2) However my books says first code is O(n^2) and second one is O(n). I don't understa... More on stackoverflow.com
🌐 stackoverflow.com
Time complexity of min(set, function)
https://pypi.python.org/pypi/pqdict/ More on reddit.com
🌐 r/Python
12
2
March 11, 2017
This question is about time complexity. For each of the given Python functions, which expect as input a non-empty list of numbers, state the time complexity in Big-O notation in terms of the length of the input list N and provide a brief explanation. a) [2 marks] def width (numbers): min = numbers [0] for n in numbers: if n < min: min = n max = numbers
a) Given function: def width(numbers): min = numbers[0] for n in numbers: if n < min: min = n max = numbers[0] for n…View the full answer ... This question is about time complexity. For each of the given Python functions, which expect as input a non-empty list of numbers, state the time ... More on chegg.com
🌐 chegg.com
1
May 28, 2020
algorithm analysis - How to find mean ,max ,min in constant time? - Computer Science Stack Exchange
I was asked to be able to find minimum, maximum and mean of a large array in constant time. I used 3 variables to track these statistics and updated them on every insert operation. I don't feel lik... More on cs.stackexchange.com
🌐 cs.stackexchange.com
December 12, 2020
🌐
CopyProgramming
copyprogramming.com › howto › time-complexity-of-min-and-max-on-a-list-of-constant-size
Python min Function Time Complexity: Complete Guide for 2026 - Python min function time complexity complete guide
February 4, 2026 - Python's built-in min() function finds the smallest item in an iterable or among arguments with O(n) time complexity, where n is the number of elements, as it scans the entire collection once. For lists of constant size, like fixed-length arrays, the time complexity remains O(1) since n equals ...
🌐
LabEx
labex.io › tutorials › python-how-to-use-default-value-in-min-function-419879
How to use default value in min function | LabEx
The min() function has a time complexity of O(n) for iterables, making it efficient for most use cases in LabEx programming environments. ... By understanding these basics, you'll be well-prepared to use the min() function effectively in your ...
🌐
Enterprise DNA
blog.enterprisedna.co › python-min-function
Python min() Function: 10 Real-World Examples – Master Data Skills + AI
The time complexity of the min function in Python is O(n), where n is the number of elements in the input iterable.
Find elsewhere
🌐
Reddit
reddit.com › r/python › time complexity of min(set, function)
r/Python on Reddit: Time complexity of min(set, function)
March 11, 2017 -

I'm implementing an algorithm and I need a data structure with both very fast lookup of arbitrary elements like you get from a hash table and similar to a priority queue very fast lookup of the highest priority element ordered by a key associated with each item.

Is there anyway I can accomplish this? I thought of just using a set and something like min(set, lambda x: x.key), would this have to iterate through all elements?

🌐
GeeksforGeeks
geeksforgeeks.org › python › complexity-cheat-sheet-for-python-operations
Complexity Cheat Sheet for Python Operations - GeeksforGeeks
July 12, 2025 - This cheat sheet is designed to help developers understand the average and worst-case complexities of common operations for these data structures that help them write optimized and efficient code in Python. Python's list is an ordered, mutable sequence, often implemented as a dynamic array. Below are the time complexities for common list operations:
🌐
Python
wiki.python.org › moin › TimeComplexity
TimeComplexity - Python Wiki
This page documents the time-complexity (aka "Big O" or "Big Oh") of various operations in current CPython. Other Python implementations (or older or still-under development versions of CPython) may have slightly different performance characteristics.
🌐
Sean Coughlin
blog.seancoughlin.me › mastering-the-minstack-efficiently-supporting-minimum-element-retrieval-in-constant-time
Efficient MinStack: Constant Time Min Element Retrieval
June 28, 2024 - To achieve constant time complexity for all operations, we use two stacks: Main Stack (stack): Stores all the elements. Minimum Stack (min_stack): Stores the minimum elements at each stage.
🌐
Medium
medium.com › @kapildevkhatik2 › how-about-python-optimization-mastering-time-and-space-complexity-for-improved-performance-e094101b42f8
Python Optimization: Mastering Time and Space Complexity for Improved Performance - Techniques for Enhanced Efficiency | Medium
June 18, 2023 - Here are some techniques for improving the time complexity of your Python code: Use built-in functions: Python provides many built-in functions that are optimized for efficiency. For example, instead of looping through a list to find the minimum value, you can use the min function.
🌐
Medium
medium.com › @ashutosh0626 › time-complexity-in-python-simply-explained-88b496f29a56
Time Complexity in Python Simply Explained | by Ashutosh Sharma | Medium
April 13, 2023 - It can be seen that for k elements n operations have been performed, so as a general rule of thumb, we try to keep our Algorithm’s time complexity below the white line which is O(n log n). ... Various functions with various time complexities.
🌐
After Academy
afteracademy.com › blog › find-the-minimum-and-maximum-value
Find minimum and maximum value in an array - Interview Problem
October 6, 2019 - int[] findMinMax(int A[], int n) ... assume ans[0] as max and ans[1] as min int ans[2] = {max, min} return ans } ... Time Complexity is O(n) and Space Complexity is O(1)....
🌐
UCI
ics.uci.edu › ~pattis › ICS-33 › lectures › complexitypython.txt
Complexity of Python Operations
If the function bodies are small, we can analyze them statically (looking at the code, not needing to run it) to determine their complexity classes. For large problem sizes, the algorithm/function with the smallest complexity class will ultimately be best, running in the least amount of time.
🌐
AlgoCademy
algocademy.com › link
Time Complexity Practice 1 in Python | AlgoCademy
In this problem, we need to analyze the time complexity of various built-in functions in Python.
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › functions › min.html
min — Python Reference (The Right Way) 0.1 documentation
Optional. Specifies a one-argument ordering function; must be in keyword form. ... When comparing sequences lexical comparison is used. >>> min(1, 2, 3) 1 >>> min('A', 'a', 'b') 'A' >>> min([1, 2], [2, 1], [3, 1]) [1, 2] >>> min(str([1, 2]), str([2, 1]), str([3, 1])) '[1, 2]'