Time Remaining, Nicely Worded

Medium ⏱ 12 min 46% acceptance ★★★★☆ 4.3
Write time_left(now, deadline) returning '<d>d <h>h <m>m' until the deadline (e.g. '2d 4h 30m'), or 'expired' if the deadline has passed. Break the timedelta down via its .days and .seconds attributes — remember .seconds excludes the days.

Examples

Example 1
Input
time_left(dt(2026,1,1,0,0), dt(2026,1,3,4,30))
Output
'2d 4h 30m'
Explanation

The delta is 2 days plus 4.5 hours.

Constraints

  • Return 'expired' when deadline <= now.
  • Minutes floor-rounded.

Topics

Date & Timetimedelta breakdown

Companies

BookMyShowFlipkartAmazon

Hints

Hint 1

delta.seconds // 3600 gives hours within the day.

Hint 2

(delta.seconds % 3600) // 60 gives minutes.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.