#345 Minimum Distance Between X and Y Characters

Companies:
Yandex
Themes:
AlgorithmsStringsPractice

A string consists of the characters 'X', 'Y', and 'O'. Find the shortest distance between 'X' and 'Y', or return 0 if either 'X' or 'Y' is absent. Examples:

"YY" -> 0
"XX" -> 0
"XY" -> 1
"YOX" -> 2
"OOOXOOYOXO" -> 2
"OOOXXOY"-> 2

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in