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
Top Distinct Distances in Pyspark
00:00
5 left

Top Distinct Distances in Pyspark

MediumPython

Problem

Pyspark question: Trips data: rider_id,client_id,start_time,end_time,vehicle_id,distance - return top 10 customers who has longest distance travelled

Asked in the technical_round_2 stage, as reported in the second EPAM onsite interview post.

Implement the equivalent algorithm as top_customers(trips). Each trip is a dictionary with integer rider_id, client_id, and vehicle_id, plus a nonnegative numeric distance. Return up to 10 [client_id, total_distance] pairs, ordered by total distance descending, then client ID ascending for ties.

Constraints

  • 0 <= len(trips) <= 1000
  • Each trip contains integer client_id and nonnegative numeric distance fields
  • 0 <= distance <= 10^9
  • The result contains at most 10 clients

Function Signature

def top_customers(trips):
Interviewer

Your question is Top Distinct Distances in Pyspark. 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.