Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Book Catalog With API
00:00
5 left

Book Catalog With API

HardPython

Problem

Create a catalog of books by fetching from an API, then add a new book and re-group and order books by user-selectable fields.

Implement the transformation after a successful API response. Input is a list of book dictionaries, one new book, a grouping field, an ordering field, and a direction. Return groups sorted by the grouping value, with each group's books sorted by the ordering value. Preserve the original order when ordering values tie.

Input: api_books, new_book, group_by, order_by, descending. Output: a list of {group, books} dictionaries.

Constraints

  • 0 <= len(api_books) <= 5000
  • Each book is a dictionary containing group_by and order_by fields
  • All group_by values are mutually comparable
  • All order_by values within a group are mutually comparable
  • descending is a boolean
  • Duplicate books are allowed and must be preserved
  • Ties in order_by must preserve combined input order

Function Signature

def build_catalog(api_books, new_book, group_by, order_by, descending):
Interviewer

Your question is Book Catalog With API. Start with the requirements in the Question tab.

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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.