I am working on below challenge
https://codingbat.com/prob/p110222
We'll say that a value is "everywhere" in an array if for every pair of adjacent elements in the array, at least one of the pair is that value. Return true if the given value is everywhere in the array.
isEverywhere([1, 2, 1, 3], 1) → true
isEverywhere([1, 2, 1, 3], 2) → false
isEverywhere([1, 2, 1, 3, 4], 1) → false
I followed below approach 1 and approach 2
Below Approach 1 passes all tests:
Below Approach 2 fails some tests
Can you please point me why exact opposite approach fails some tests.
To begin with how to choose approach 1 instead of approach 2 without trial and error?