Squares of Sorted Array
easyReturn squares of sorted array in sorted order (handles negatives)
Squares of Sorted Array
Key Insight
Largest squares at ends (negatives). Compare ends, fill result from back.
Step 1Setup
(-4)²=16, 10²=100
left
-4
0-1
10
23
3right
10
4→converge←
Array has negatives. Largest squares are at the ends.
1 / 5