Skip to content
← Back to the archive

2 September 2026

Library Fines

Medium Lists Numbers

Work out the fine for each book that was returned late.

A library allows readers a short grace period before charging late fines on book returns. You are given the number of days late for each returned book, the number of days grace, and the cost of the fine for each day beyond the grace period. For each book, calculate its fine: - A book returned within the grace period has no fine. - Otherwise, total up the daily fines only for the days after the grace period. Return the fines in the same order as the books. Return an empty list when there are no books.

Constraints

  • days_late contains at most 100 non-negative whole numbers
  • free_days and daily_fine are non-negative whole numbers
  • Each fine is calculated separately for one book

Function signature

def library_fines(days_late, free_days, daily_fine):

Sign in to solve this bracket

Reading the problem is free for everyone. Opening the editor and solving it requires an account with Open Bracket+.