Solve an array-based problem, such as finding duplicate elements or identifying pairs that sum to a specific target.
Implement two_sum(nums, target) to return the indices of the two distinct elements whose values add up to target. Each valid input contains exactly one solution, and the returned indices must be in their original array order. Return an empty list only if no pair exists.
Input: an integer list nums and integer target. Output: a two-element list of indices.
def two_sum(nums, target):