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
Count Same Bid History Fast
00:00
5 left

Count Same Bid History Fast

EasyPython

Problem

Quantcast's real-time bidding service needs to answer how often a proposed bid has appeared in a historical sequence. Implement count_in_history so repeated lookups remain efficient when the history contains millions of bids.

The historical bids are provided in nondecreasing order. Return the number of elements equal to current_bid. Do not modify previous_bids.

Formal Specification

  • Input current_bid: an integer bid value.
  • Input previous_bids: a nondecreasing array of integers representing prior bids.
  • Output: an integer count of values in previous_bids equal to current_bid.

Use the sorted property to avoid scanning the complete array. A solution that performs one full pass per request is not considered optimal for this interface.

Constraints

  • 0 <= previous_bids.length <= 10^7
  • -10^9 <= current_bid <= 10^9
  • -10^9 <= previous_bids[i] <= 10^9
  • previous_bids is sorted in nondecreasing order
  • previous_bids must not be modified

Function Signature

def count_in_history(current_bid, previous_bids):
Interviewer

Your question is Count Same Bid History Fast. 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.