Given a list of records (name, stock value, date), write functions that consume the data and return calculations such as the top 5 stocks within a date range.
Asked in the Karat screen stage. Reported follow-ups included other similar calculations on the same data.
Implement top_five_stocks(records, start_date, end_date). Each record is a dictionary with name as a string, value as a number, and date as an ISO YYYY-MM-DD string. Include both date boundaries. Aggregate values by name, rank by descending total value, break ties by ascending name, and return at most five (name, total_value) pairs.
def top_five_stocks(records, start_date, end_date):