Overview


We are looking for "closest" to either end so that means we only care about the "first match" (from left/start) and "last index" (from last/end).

Sample #1


Given: [5, 5, 5, 5, 5, 5, 3]
Say we look for a match of "5"


Sample #2


Given: [8, 9, 5, 5, 5, 5, 5, 5, 0]
Say we look for a match of "5"