Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Array or Hash Map Coding Solution

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

Your question is Array or Hash Map Coding Solution. 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

CrowdStrike Falcon telemetry can assign numeric scores to endpoint events for prioritization. Given an array of event scores and a target score, find the two distinct events whose scores add up to the target.

Return the zero-based indices of the two events in increasing order. Each input contains exactly one valid pair, and the same array element cannot be used twice.

Formal Specification

Implement two_event_scores(scores, target).

  • Input: scores, a list of integers, and target, an integer.
  • Output: A list containing two integers, the indices i and j where i < j and scores[i] + scores[j] == target.

Use a hash map to support constant-time average lookup of a previously seen complement. The function should scan the array once rather than checking every pair.

Constraints

  • 2 <= len(scores) <= 100,000
  • -10^9 <= scores[i] <= 10^9
  • -10^9 <= target <= 10^9
  • Exactly one valid pair exists
  • The same array element cannot be used twice

Function Signature

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