Check if array contains nearby duplicates

I like this suggestion, works just fine and is quite easy for me to understand. Thanks for the resources.