## Problem https://leetcode.com/problems/sum-of-squares-of-special-elements/description/ <br> :::spoiler **Optimal Space & Time Complexity** ``` - Time complexity: O(squr(n)) - Space complexity: O(n) ``` ::: <br> <hr/> ## Solutions :::spoiler 東 ```javascript= ``` ::: <br> :::spoiler Hao ```javascript= ``` ::: <br> :::spoiler YC ```javascript= ``` ::: <br> :::spoiler SOL ```javascript= ``` ::: --- ## Supplement / Discussion ### 東 ### Hao Like [the solution](https://leetcode.com/problems/sum-of-squares-of-special-elements/solutions/3780956/simple-javascript-solution/) here, intrusively, the time complexity and space complexity would both be O(n), while the time complexity could be optimized to be O(squr(n)). [The optimized solution](https://leetcode.com/problems/sum-of-squares-of-special-elements/solutions/3787264/javascript-sqrt-n-runtime-with-explanation-math/) employ the concept that set (i * i < n) as the condition the loop runs, which efficiently filter out the elements we want. Say i * i = n, then we could find the rules that 1 * x = n 2 * y = n 3 * z = n ... i * i = n ### YC ### SOL