Hudl Sportscode records player substitutions as timestamped events during a match. Given the players on court at the start, substitution events, and the final match timestamp, calculate the total number of seconds each player was on the court.
Implement calculate_court_time(initial_players, events, end_time).
initial_players is a list of player ID strings on court at timestamp 0.events is a list of events represented as [timestamp, player_id, action], where action is either "in" or "out".end_time is the nonnegative integer timestamp when the match ends.initial_players or events to their total court time in seconds. Players who never enter must have a total of 0.Assume all timestamps are integers in [0, end_time], the input describes valid substitutions, and a player cannot be both on and off the court at the same time.
def calculate_court_time(initial_players, events, end_time):