Approach Summary
Use two pointers at each end, compare absolute values, fill result array from the back.
How to Recognize This Pattern
- Sorted array with negatives, need sorted squares
- Largest squares are at the ends
Complexity Analysis
Time Complexity
O(n)
Space Complexity
O(n)
Tags
Array Two Pointers Sorting