# Leetcode 821 - Shortest Distance to a Character

Note:

• Key part is how to find the first element in occurence[] that is bigger than index i.
• Three situations:
• Before occurence[0]
• Between two occurence
• After last occurence.

Question:

Given a string s and a character c that occurs in s, return an array of integers answer where answer.length == s.length and answer[i] is the distance from index i to the closest occurrence of character c in s.

The distance between two indices i and j is abs(i - j), where abs is the absolute value function.

Example:

Code: