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
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
Sorting Property Data by Criteria
00:00
5 left

Sorting Property Data by Criteria

EasyPython

Problem

Zillow listing cards can be sorted by several user-selected criteria, such as price, bedrooms, or address. Implement a function that returns the properties in the requested priority order.

Formal Specification

Write sort_properties(properties, criteria), where:

  • properties is a list of dictionaries. Each dictionary contains numeric fields price, bedrooms, bathrooms, and days_on_zillow, plus a string field address.
  • criteria is a non-empty list of dictionaries. Each criterion has a valid field and an order, either "asc" or "desc". Criteria are listed from highest to lowest priority.
  • Return a new list containing the same property dictionaries, sorted according to every criterion. Do not mutate the input list.
  • Sorting must be stable: properties equal under all criteria retain their original relative order.

Constraints

  • 1 <= len(properties) <= 10^5
  • 1 <= len(criteria) <= 5
  • Each criterion field exists in every property
  • Each criterion order is either "asc" or "desc"
  • Criterion fields are unique
  • Numeric property fields are non-negative

Function Signature

def sort_properties(properties, criteria):
Interviewer

Your question is Sorting Property Data by Criteria. 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.