colors
array and append the index to the corresponding color's list in the hashmap.(i, c)
:
a. Check if color c
is in the hashmap. If not, return -1
.
b. Perform a binary search on the list of indices for color c
to find the closest index to i
.
c. If i
is less than the first index in the list, return the distance to the first index.
d. If i
is greater than the last index in the list, return the distance to the last index.
e. Otherwise, find the closest index on either side of i
and return the minimum distance.