Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Format Data for UI Display

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Format Data for UI Display. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Crunchyroll receives a flat array of episode records, but its watchlist UI displays episodes grouped by series and season. Implement a formatter that creates this nested display structure and derives a progress percentage and viewing status for every episode.

Formal Specification

Implement format_watchlist(items), where items is a list of dictionaries. Each dictionary contains:

  • series_id: string
  • series_title: string
  • season: positive integer
  • episode: positive integer
  • episode_title: string
  • duration_seconds: positive integer
  • position_seconds: nonnegative integer
  • watched: boolean

Return a list of series dictionaries sorted by series_title without regard to case. Each series must contain seriesId, title, and seasons. Each season must contain seasonNumber and an episodes list. Sort seasons numerically and episodes numerically.

Each formatted episode must contain episodeNumber, title, progressPercent, and status. A watched episode has status Watched and progress 100. Otherwise, progress is the integer percentage of position_seconds / duration_seconds, capped at 100. Status is In Progress when progress is greater than zero, and Not Started otherwise.

Constraints

  • 0 <= items.length <= 10^4
  • Each series, season, and episode combination appears at most once
  • 1 <= duration_seconds <= 10^7
  • 0 <= position_seconds <= 10^7

Function Signature

def format_watchlist(items):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output