DEV Community

Discussion on: Using Two-Pointer Technique to Optimize Algorithm Solutions

liaowow profile image
Annie Liao Author • Edited

OK, so this approach only works when the input is sorted, as mentioned in the problem statement: "Given a sorted (ascending) array of integers, write a function that returns a sorted (ascending) array which contains the square of each number."

I know, it's not ideal, but please let me know if you have an optimized solution for an unsorted input. In any case, thanks for pointing it out and testing both functions!