visited
set to keep track of visited indices.graph
dictionary that maps each value to a list of indices with that value.visited
set.
d. Enqueue the neighboring indices (i+1, i-1) if they are within bounds and not visited.
e. Enqueue all indices with the same value as the current index from the graph
and clear the list in the dictionary.