• + 13 comments

    You may try this too,

    Works even for the test case:

    5

    1 2 2 2 1

    Output: 2

    read
    arr=($(cat))
    arr=${arr[*]}
    echo $((${arr// /^}))