← Pinterest Interview Insights
The deduplication part was fine but I initially used a global set across all users which tanked my space complexity.
Clarify edge cases (empty mapping, None values, duplicate pins) and state assumptions. Use a set per user to deduplicate pins while ignoring None, then compute the mean of set sizes. Ensure O(total items) time by iterating each list once and O(unique pins) space by storing only unique pins per user.
Pro tip: Mention that using a set per user is optimal for deduplication, but if memory is a concern, you could process users sequentially and reuse a single set, clearing it between users—this keeps space O(max unique pins per user) rather than O(total unique pins).
Ask about empty mapping, None values, duplicate pins, and whether the mean should be computed over all users or only those with pins. Confirm rounding behavior.
Use a set per user to track unique pin IDs, ignoring None. This gives O(1) average insertion and deduplication.
Loop through each user's list, add non-None pins to the set, then record the set size. Sum these sizes and count users.
Divide the total unique pins by the number of users (or return 0 if no users). Round to two decimal places using appropriate rounding (e.g., round half up).
Explain that time is O(total items) because each pin is processed once, and space is O(unique pins) due to the sets.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.