Hard
Algorithm Optimization Challenge
Optimize a given inefficient algorithm for space and time complexity.
📝 Conteúdo do Prompt
Analyze the following O(n^2) algorithm snippet: for i in 0 to n: for j in i+1 to n: if arr[i] + arr[j] == target: return [i, j]. Refactor this logic to achieve O(n) time complexity using a hash map. Explain the trade-offs made during the optimization process regarding memory usage and CPU cycles.