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
Sliding Window Packet Label Counts
00:00
5 left

Sliding Window Packet Label Counts

MediumPython

Problem

Given timestamps[] of packet arrivals and labels[], a target_label and window_size, return the count of packets with target_label in each sliding window of window_size seconds, moving one second at a time.

Asked in the tech screen stage. Treat each window as half-open, [start, start + window_size). Produce one count for every integer start from the minimum timestamp through the maximum timestamp, inclusive.

Formal Specification

Implement count_target_packets(timestamps, labels, target_label, window_size). timestamps and labels are equally sized lists, and labels[i] belongs to the packet arriving at timestamps[i]. Return a list of integers. Timestamps are sorted in nondecreasing order, and window_size is positive.

Constraints

  • 0 <= len(timestamps) = len(labels) <= 10^3
  • timestamps are integers in nondecreasing order
  • 1 <= window_size
  • labels and target_label are strings

Function Signature

def count_target_packets(timestamps, labels, target_label, window_size):
Interviewer

Your question is Sliding Window Packet Label Counts. 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.