Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Hash Map Coding Problem

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Hash Map Coding Problem. Start with the requirements on the right.

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.

Problem

Agoda analyzes sequences of daily booking-demand adjustments for hotel search results. Given an integer array and a target value, count how many contiguous, non-empty subarrays have a sum exactly equal to the target.

Formal Specification

Implement count_demand_windows(demand, target).

  • Input: demand, a list of integers, and target, an integer.
  • Output: Return an integer representing the number of contiguous non-empty subarrays whose elements sum to target.
  • Values may be positive, zero, or negative.

Constraints

  • 1 <= len(demand) <= 10^5
  • -10^4 <= demand[i] <= 10^4
  • -10^9 <= target <= 10^9
  • The answer fits in a signed 64-bit integer.

Function Signature

def count_demand_windows(demand, target):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output