Try doing it with recursion, checking each pair (or the one before if you’re skipping this one), rather than checking the entire array every iteration.
Try doing it with recursion, checking each pair (or the one before if you’re skipping this one), rather than checking the entire array every iteration.