Write a function in your preferred language to find duplicate elements in an array.
Return each duplicated value once, in the order its second occurrence is encountered. Use def find_duplicates(arr):; the input is a list of integers and the output is a list of integers. Return [] when no value appears more than once. Assume 0 <= len(arr) <= 10^4.
def find_duplicates(arr):