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
Card Usage Over Time
00:00
5 left

Card Usage Over Time

MediumPython

Problem

Given an interface, implement a solution to check whether a card was used more than X times in the last X hours.

Asked in the HackerRank assessment stage. Java question 1.

Implement is_overused(card_id, usage_times, x, current_time). card_id is a string, usage_times is a list of integer timestamps in hours, x is a positive integer, and current_time is the ending timestamp. Count usages in the inclusive interval [current_time - x, current_time]. Return True only when that count is greater than x; otherwise return False. Usage timestamps may be unsorted, and timestamps outside the interval must not be counted.

Constraints

  • 1 <= x <= 10^9
  • 0 <= len(usage_times) <= 10^4
  • Each timestamp is an integer
  • current_time is an integer
  • usage_times may be unsorted
  • The interval boundaries are inclusive

Function Signature

def is_overused(card_id, usage_times, x, current_time):
Interviewer

Your question is Card Usage Over Time. 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.