Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Process JSON and Filter Results

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

Your question is Process JSON and Filter Results. 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

Asurion Home+ receives a nested device catalog payload. Transform it into a flat list of eligible offers for a customer.

Implement filter_home_plus_offers(payload, category, max_price, min_rating). Include an offer only when its device has status equal to "active", its category matches the requested category, its available field is true, its price is at most max_price, and its rating is at least min_rating. If the same offerId appears more than once, keep only the occurrence with the lowest price. Return the results sorted by ascending price, then ascending offerId.

Formal Specification

  • payload is a dictionary with a devices list.
  • Each device contains string fields deviceId, brand, category, and status, plus an offers list.
  • Each offer contains string fields offerId and title, numeric fields price and rating, and a boolean field available.
  • Return a list of dictionaries containing exactly deviceId, brand, offerId, title, and price.

Constraints

  • The payload contains at most 10^4 devices and 10^5 offers.
  • Prices are nonnegative numbers.
  • Ratings are between 0 and 5.
  • Each offer has all required fields.
  • Offer IDs are nonempty strings.

Function Signature

def filter_home_plus_offers(payload, category, max_price, min_rating):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output