user
Write a code to detect duplicates in an array.

[3, 2, 1, 2, 3, 4]


assistant
"""
# Find duplicate elements in a list

def find_duplicates(data):
    seen = set()
    duplicates = []

    for element in data:
        if element in seen:
            duplicates.append(element)
        else:
            seen.add(element)
    
    return duplicates

if __name__ == "__main__":
    arr = [3, 2, 1, 2, 3, 4]
    duplicates = find_duplicates(arr)
    print(duplicates)
"""