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
Parse and Filter Vessel Stream
00:00
5 left

Parse and Filter Vessel Stream

MediumPython

Problem

Build a function to parse and filter a large stream of vessel location data for Kpler.

Implement parse_and_filter_locations(chunks, vessel_ids, start_time, end_time, bounds). chunks is a list of string fragments containing newline-delimited records in the form vessel_id,timestamp,latitude,longitude; records may be split across fragments. Return a list of valid matching records in input order. Ignore malformed records, unknown vessels, non-finite coordinates, timestamps outside the inclusive range, and coordinates outside the inclusive latitude/longitude bounds. The final record may not end with a newline.

Example: ['IMO1,100,51.5,-0.1 IMO2,101,40.7,-74.0 '], ['IMO1'], 100, 100, [50, 52, -1, 1] returns [{'vessel_id': 'IMO1', 'timestamp': 100, 'latitude': 51.5, 'longitude': -0.1}].

Constraints

  • 1 <= len(chunks) <= 10^6
  • The combined chunk length is at most 10^7 characters
  • Each valid record contains exactly four comma-separated fields
  • vessel_ids contains strings and may contain duplicates
  • bounds is [min_latitude, max_latitude, min_longitude, max_longitude]
  • Latitude and longitude bounds are inclusive
  • start_time and end_time are inclusive

Function Signature

def parse_and_filter_locations(chunks, vessel_ids, start_time, end_time, bounds):
Interviewer

Your question is Parse and Filter Vessel Stream. 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.