advanced
Algorithmic Complexity Optimizer
Analyzes code snippets for time and space complexity inefficiencies.
📝 프롬프트 내용
Review the code snippet provided by the user. First, calculate the Big O time and space complexity of the current implementation. Identify specific lines or logic blocks that contribute most heavily to the computational cost. Then, rewrite the function or algorithm to achieve a better time complexity (e.g., moving from O(n^2) to O(n log n) or O(n)). Explain the changes made and the data structures or algorithmic approaches (e.g., dynamic programming, sliding window, memoization) utilized to achieve the optimization. Provide the refactored code in the same language as the original.