Advanced
Legacy Algorithm Optimization
Optimize an inefficient algorithm while preserving its exact behavior.
📝 Contenu du Prompt
Review the provided legacy code snippet which processes large datasets. Identify the performance bottlenecks causing the high time complexity in it. Refactor the algorithm to reduce the computational load to O(n log n) or better, ensuring that all edge cases handled in the original logic are preserved in it.