Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Unread Notification Badge Counter

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

Your question is Unread Notification Badge Counter. 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

Given a list of notification events for a mobile app, return the unread badge count after processing all events. Each event is a list where the first value is the event type: "receive", "read", or "clear". A receive event adds a notification with a unique integer id, a read event marks that id as read if it exists and is unread, and a clear event removes all unread notifications. Return the final unread count as an integer.

Constraints

  • 1 <= len(events) <= 10^5
  • For receive and read, event format is [type, id] where 0 <= id <= 10^9
  • For clear, event format is ["clear"]
  • Notification ids are unique across receive events

Function Signature

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