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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
API Fetch and Search in a Project
00:00
5 left

API Fetch and Search in a Project

HardPython

Problem

Describe a time you worked on a project where you retrieved data from an API, displayed it on a screen, and added search functionality.

Implement search_api_results(pages, query, limit) for a paginated API response. Deduplicate items by first-seen id, match the query as a contiguous sequence of words in either title or description, rank title matches before description matches, preserve API order for ties, and return at most limit IDs. Matching is case-insensitive, and an empty query returns the first items in API order.

Contract

pages is a list of pages containing dictionaries with integer id and string title and description; return a list of integer IDs.

Constraints

  • 0 <= number of pages <= 100
  • 0 <= total number of API items <= 1,000
  • Each item contains an integer id and string title and description
  • 0 <= limit <= 1,000
  • Query matching is case-insensitive and uses contiguous word sequences

Function Signature

def search_api_results(pages, query, limit):
Interviewer

Your question is API Fetch and Search in a Project. 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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.