Write a simple program, such as a two-sum implementation, and explain how you would optimize its performance.
Implement two_sum(nums, target), returning the indices of two distinct elements whose values add to target. Return an empty list if no pair exists, and discuss the time and space trade-offs between brute force and an optimized approach.
def two_sum(nums, target):