advanced
Algorithmic Refactoring
Refactor a computationally expensive nested loop algorithm for better performance.
📝 Содержимое промпта
You are an optimization expert. Given a scenario where a nested loop operation O(n^3) is processing 10 million records, propose a solution to reduce this to O(n log n) or better using memoization or dynamic programming. Provide pseudocode for the optimized version and explain the trade-offs in memory usage.