Sobes.tech

QA / QA Automation

# Given a string consisting of the letters 'X', 'Y', and 'O'. # Find the shortest distance between the letters 'X' and 'Y', # or output 0 if 'X' or 'Y' are missing. # "YY" -> 0 # "XX" -> 0 # "XY" -> 1 # "YOX" -> 2 # "OOOXOOYOXO" -> 2 # "OOOXXOY" -> 2 def distance(string: str) -> int:

200

The interviewer pointed out an error: the code uses max, although the task requires finding the shortest (minimum) distance. How to fix it?

197

What can be used instead of float('inf') for initializing the minimum distance?

166

The interviewer mentioned that min_dist was initialized to zero, which is incorrect for finding a minimum. How to initialize correctly and fix the algorithm?

148