• + 0 comments
    read N
    read -a arr
    
    # We create the variable found to help us iterate
    found=0
    while [[ ${#arr[@]} -gt 1 ]]; do
        # We create an array with the existent indexes
        idx=()
        for i in ${!arr[@]}; do
            idx+=("$i")
        done
        
        # We pick the first value
        check=${arr[${idx[$found]}]}
        
        # We start the counter of matches
        count=0
        
        # We check the array counting matches
        for i in ${!arr[@]}; do
            if [[ "${arr[$i]}" -eq "$check" ]]; then
                ((count++))
            fi
        done
        
        # We check how many matches we have
        if [[ $count -eq 2 ]]; then
            # If we have 2 matcher, we delete ALL matches
            for i in ${!arr[@]}; do
                if [[ "${arr[$i]}" -eq "$check" ]]; then
                    unset arr[$i]
                fi
            done
        else
            # Else, we have 1 match, aka the lonely integer
            # We increase the found, so the check value skips the one
            ((found++))
        fi
    done
    echo "${arr[@]}"