Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Arrays and Hashmaps Coding

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

Your question is Arrays and Hashmaps Coding. 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

Gro Intelligence's Data API can provide ordered daily climate anomaly values for a region. Given these values and a target total, count how many contiguous periods have a sum exactly equal to the target.

Values may be positive, negative, or zero. Two periods are different if they have different start or end indices.

Formal Specification

Implement count_target_windows(values, target).

  • values is a list of integers representing ordered daily anomaly values.
  • target is an integer total.
  • Return an integer equal to the number of contiguous non-empty subarrays whose values sum to target.

Constraints

  • 1 <= len(values) <= 100,000
  • -10^9 <= values[i] <= 10^9
  • -10^14 <= target <= 10^14
  • Values may be positive, negative, or zero

Function Signature

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