medium
Optimize Python Function
Refactor a Python function for better performance.
📝 প্রম্পট বিষয়বস্তু
Review the following Python function and suggest optimizations to improve its time complexity. Explain the changes made and provide the refactored code.