medium
Optimize Python Function
Refactor a Python function for better performance.
📝 Prompt Content
Review the following Python function and suggest optimizations to improve its time complexity. Explain the changes made and provide the refactored code.