Frequency Tracker

[Frequency Tracker]
(Snowflake/Meta/Amazon)
Design and implement a class FrequencyTracker that efficiently manages key-frequency pairs. The data structure should support the following operations:

1. add(key): Increment the frequency of the given key by 1.
2. delete(key): Decrement the frequency of the given key by 1. If the frequency becomes 0, remove the key from the data structure.
3. key_with_max_frequency(): Return any key with the highest frequency.
4. key_with_min_frequency(): Return any key with the lowest frequency (excluding keys with frequency 0).

All operations must have O(1) time complexity...



Get one-to-one training from Google Facebook engineers

Top-notch Professionals

Learn from Facebook and Google senior engineers interviewed 100+ candidates.
Most recent interview questions and system design topics gathered from aonecode alumnus.
One-to-one online classes. Get feedbacks from real interviewers.

Customized Private Class

Already a coding expert? - Advance straight to hard interview topics of your interest.
New to the ground? - Develop basic coding skills with your own designated mentor.
Days before interview? - Focus on most important problems in target company question bank.