The nickname back then

Write code · Medium · §8.2 Writing binary search yourself

Each time the user set or changed their nickname, a record [time, nickname] was added to logs, in order of time. The first record holds the nickname chosen at sign-up. If several records have the same time, the one later in logs is the later change.

The nickname shown at time t is the nickname of the record that comes last in logs among the records whose time is at most t. If t is earlier than the time of the first record, the user had not signed up yet, so the nickname shown is an empty string "".

times holds the times when this user's comments were reported. Complete the function solution, which returns a list of the nickname shown at each time, in the same order as times.

Function

solution(logs, times)

Constraints

Examples

logstimesresult
[[10, 'mina'], [25, 'mina2'], [40, 'sky']][30, 12]['mina2', 'mina']
[[3, 'kim'], [8, 'lee'], [9, 'park'], [20, 'choi']][10, 4, 15]['park', 'kim', 'park']

Starter code

def solution(logs, times):
    answer = []
    return answer

Solve this problem in your browser

Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.