Interview Query

Closest Key

1
Have you seen this question before?

Given a dictionary with keys of letters and values of a list of letters, write a function closest_key to find the key with the input value closest to the beginning of the list.

Example:

Input:

dictionary = {
    'a' : ['b','c','e'],
    'm' : ['c','e'],
}
input = 'c'

Output:

closest_key(dictionary, input) -> 'm'

cc is at distance 1 from aa and 0 from mm. Hence closest key for cc is mm.

Next question: Find the missing number
.....
Python 3.9.6
Loading editor
Use Shift + Enter to run code