text and a letter mark that appears in text at least once.
For every position i of the string, find how far away the nearest occurrence of mark is. The distance between positions i and j is |i - j|; if mark itself sits at position i, the distance is 0.
Return a list of length len(text) whose i-th element is the distance for position i.text='banana', mark='n' → [2, 1, 0, 1, 0, 1]
The letter n sits at positions 2 and 4. Position 0 is two steps from the nearest n, position 3 is one step from either of them, and the last position 5 is one step back.
text='zzzq', mark='q' → [3, 2, 1, 0]
The only q is at the very end, so the distances simply count down towards it: 3, 2, 1, 0.
text='x', mark='x' → [0]
len(text) ≤ 10⁵text and mark consist of lowercase English letters, and mark is a single lettermark occurs in texttext='banana', mark='n'
[2, 1, 0, 1, 0, 1]
Run checks the first 3 tests in your browser. Submit checks all 121 tests on the server, hidden ones included.