480. Shortest Distance to a Character
EasyTwo Pass
For each position in s, print the distance to the nearest occurrence of character c (c occurs at least once).
Input format
Line 1: s Line 2: c
Output format
|s| distances.
Example 1
Input
loveleetcode e
Output
3 2 1 0 1 0 0 1 2 2 1 0
Example 2
Input
aaab b
Output
3 2 1 0
Constraints
1 ≤ |s| ≤ 10⁴
Read input from standard input and print the answer to standard output. Your code is judged against 3 test cases, most of them hidden.
Loading the MyLoginn IDE…