Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Hash Map and Set Program

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

Your question is Hash Map and Set Program. 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

The Airtel Thanks app records successful feature events as they occur. Given an event stream and a list of required features, return the subscriber ID of the first subscriber who has successfully used every required feature. Duplicate events for the same subscriber and feature should count only once.

Use a hash map to associate each subscriber with a set of features they have used. Return None if no subscriber completes the required feature set.

Formal Specification

Implement first_complete_subscriber(events, required_features).

  • events is a list of two-element lists [subscriber_id, feature], processed in order.
  • required_features is a list of distinct feature names.
  • subscriber_id and feature are strings.
  • Return the subscriber ID as a string, or None if completion never occurs.
  • If required_features is empty, return None.

Constraints

  • 1 <= len(events) <= 10^5
  • 1 <= len(required_features) <= 10^4
  • Each event contains exactly two strings
  • Feature names in required_features are distinct

Function Signature

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