PracHub
QuestionsLearningGuidesInterview Prep

Quick Overview

This question evaluates data manipulation and aggregation skills, focusing on handling duplicate values within collections and computing numerical summaries of list data.

  • medium
  • TikTok
  • Coding & Algorithms
  • Data Scientist

Compute Averages of Unique Numbers in Dictionary Lists

Company: TikTok

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

##### Scenario Python tech screen: given a dictionary mapping keys to numeric lists, e.g., {'a':[1,2,1],'b':[1,2,3]}, compute the average of each list after removing duplicates. ##### Question Write Python code that takes any such dictionary and returns a new dictionary whose values are the average of the unique numbers in each original list. ##### Hints Deduplicate each list (set or list(dict.fromkeys())), then take the mean.

Quick Answer: This question evaluates data manipulation and aggregation skills, focusing on handling duplicate values within collections and computing numerical summaries of list data.

Given a dictionary mapping strings to lists of numbers (integers or floats), return a new dictionary mapping each key to the arithmetic mean of the unique numbers in its list. Duplicates within a list are ignored. If a list is empty, return 0.0 for that key.

Constraints

  • 0 <= number of keys <= 10^4
  • 0 <= length of each list <= 10^5
  • Sum of lengths across all lists <= 2 * 10^5
  • Values are integers or floats in the range [-1e9, 1e9]
  • Integers and floats equal by value (e.g., 1 and 1.0) are considered duplicates
  • If a list is empty, the average for that key is 0.0

Hints

  1. Use a set to deduplicate each list before averaging.
  2. Compute the mean as sum(unique)/len(unique); if unique is empty, use 0.0.
  3. Note that 1 and 1.0 are treated as the same value when deduplicating.
Last updated: Mar 29, 2026

Loading coding console...

PracHub

Master your tech interviews with 9,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Parse a nested list from a string - TikTok (medium)
  • Implement stacks, streaming median, and upward path sum - TikTok (easy)
  • Maximize sum with no adjacent elements - TikTok (medium)
  • Solve common string/DP/stack problems - TikTok (medium)
  • Find the longest palindromic substring - TikTok (easy)