There are a lot of ways to solve this problems.
First approach could be to use priority queue to store the ranks O(log(n)) and take k-th eleement with klog(n)
Second could be to use augmented balanced binary search tree, again store with O(log(n)) and take k-the element with O(log(k))
For the interview I am not sure that you can implement balanced tree, maybe binary search tree with augmented data if the second approach is preferred.
dist1 = list()
dist2 = list()
dist = list()
for i,j in enumerate(words):
if j == word1:
elif j == word2:
dist = [abs(x -y) for x in dist1 for y in dist2]