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
Start free
Array Intersection and Cheapest Prefix
00:00
5 left

Array Intersection and Cheapest Prefix

MediumPython

Problem

Scribd's recommendation pipeline receives a sequence of book IDs with prices and a second array containing eligible book IDs. Return every book from the first array that appears in the second array, preserving order. For each matching position i, also return the cheapest price strictly before position i in the first array.

If no price exists before i, return None for that book. Duplicate IDs in the first array should produce duplicate output entries. Membership in the second array is treated as a set, so duplicates there do not change the result.

Formal Specification

Implement intersect_with_prior_min(book_ids, eligible_ids, prices). book_ids and prices are arrays of equal length, and eligible_ids is another integer array. Return an array of two-element arrays, where each element is [book_id, prior_min_price].

Constraints

  • 1 <= len(book_ids) = len(prices) <= 10^5
  • 0 <= len(eligible_ids) <= 10^5
  • 0 <= book_ids[i], eligible_ids[i] <= 10^9
  • 0 <= prices[i] <= 10^9
  • Preserve the order of matching elements from book_ids

Function Signature

def intersect_with_prior_min(book_ids, eligible_ids, prices):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

Sign up free to run or submit. Log in
Code
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 2
Run your code to see test output here.