Advanced
Big-O Complexity Optimization
Optimize a given algorithm for better time and space complexity.
📝 Prompt Inhoud
Review the following Python function. Determine its current time and space complexity using Big-O notation. Identify the bottlenecks and rewrite the function to improve efficiency by at least one order of magnitude while maintaining functionality.