"""
Exercise 1: Squares of a Sorted Array (LeetCode 977)

nums is sorted ascending and may contain negatives. Return the squares of
each number, sorted ascending, in O(n) (no sort call).

Hint: the largest square is at one of the two ENDS. Fill the result from
the back with two pointers.

  sorted_squares([-4, -1, 0, 3, 10]) -> [0, 1, 9, 16, 100]
"""

def sorted_squares(nums):
    # TODO: two pointers from both ends, fill result right-to-left
    pass


# --- self-check: do not modify below this line ---
cases = [([-4, -1, 0, 3, 10], [0, 1, 9, 16, 100]), ([-7, -3, 2, 3, 11], [4, 9, 9, 49, 121]), ([], []), ([-2], [4]), ([1, 2], [1, 4])]
ok = True
for nums, want in cases:
    got = sorted_squares(nums)
    print(nums, "->", got)
    ok = ok and got == want
print("PASS" if ok else "FAIL")
