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!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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!