Hackbright Code Challenges

Most Active Period

Most Active Period

Whiteboard

Harder

Challenge

Medium

Concepts

Logic, Loops

Download

most-active.zip

Solution

Most Active Period: Solution


In this challenge, you will find the window of time when the most authors were active.

You have biographic data like this:

Name

Start

End

Alice

1901

1950

Bob

1920

1960

Carol

1908

1945

Dave

1951

1960

All authors become active on or after the year 1900. All stopped being active on or before 1999.

For this data, there is one period, 1920-1945, where there were three authors active (Alice, Bob, and Carol). Therefore, this is the range you want to find.

You should write a function, most_active, which takes biographical data and returns a tuple of (window-start, window-end), like this:

>>> data = [
...    ('Alice', 1901, 1950),
...    ('Bob',   1920, 1960),
...    ('Carol', 1908, 1945),
...    ('Dave',  1951, 1960),
... ]

>>> most_active(data)
(1920, 1945)

If there’s more than one period with the same number of active authors, find the earliest:

>>> data = [
...    ('Alice', 1901, 1950),
...    ('Bob',   1920, 1960),
...    ('Carol', 1908, 1945),
...    ('Dave',  1951, 1960),
...    ('Eve',   1955, 1985),
... ]

>>> most_active(data)
(1920, 1945)

(Alice, Bob, Carol were active 1920-1945. Bob, Dave, and Eve were active 1951-1960. Since there’s a tie, the first was returned)

Your program should run in linear O(n) time.

We’ve given you a function, most_active. Implement it:

active.py
def most_active(bio_data):
    """Find window of time when most authors were active."""