Shortest distance between X and Y in a string

0
Practice

Find the shortest distance between characters X and Y in a string in one pass. Reported on 1point3acres' Glean bank; reconstructed in our own words.

GleanCoding
No answer yet. Write the first one; the best answer gets endorsed.