#K45037. Shortest Distance to a Character
Shortest Distance to a Character
Shortest Distance to a Character
Given a string \(s\) consisting of lowercase English letters and a character \(c\), find the shortest distance from each character in \(s\) to the character \(c\). The distance between indices \(i\) and \(j\) is defined as \(|i - j|\).
For example, if \(s = \text{loveleetcode}\) and \(c = e\), then the expected output is [3, 2, 1, 0, 1, 0, 0, 1, 2, 2, 1, 0]
.
inputFormat
The input is read from standard input (stdin) and consists of two lines. The first line contains the string \(s\). The second line contains the character \(c\) which is guaranteed to appear in \(s\).
outputFormat
The output should be printed to standard output (stdout) as a sequence of integers separated by spaces. The \(i\)-th integer represents the shortest distance from \(s[i]\) to the character \(c\).
## sampleloveleetcode
e
3 2 1 0 1 0 0 1 2 2 1 0