Untitled
from datetime import datetime, timedelta def highest_consecutive_dates(dates_list): # Convert string dates to datetime objects dates = sorted([datetime.strptime(date, "%Y-%m-%d") for date in dates_list]) max_consecutive = 1 current_streak = 1 for i in range(1, len(dates)): if dates[i] == dates[i - 1] + timedelta(days=1): current_streak += 1 else: max_consecutive = max(max_consecutive, current_streak) current_streak = 1 # Check for the last streak max_consecutive = max(max_consecutive, current_streak) return max_consecutive # Example usage dates_list = ["2024-01-01", "2024-01-02", "2024-01-03", "2024-01-05", "2024-01-07", "2024-01-08"] result = highest_consecutive_dates(dates_list) print("Highest number of consecutive dates:", result)
Leave a Comment