Design the logic for a logger (solved with a sliding window), with a follow-up needing a different algorithm.
Asked in the onsite DSA 3 stage.
Implement should_print_message(timestamp, message, last_seen). Return True if the message has not been printed during the previous 10 seconds, otherwise return False. When returning True, update last_seen with the message's timestamp. Timestamps arrive in nondecreasing order. Discuss a follow-up where timestamps may arrive out of order and explain why the original approach is insufficient.
def should_print_message(timestamp, message, last_seen):