PracHub
QuestionsLearningGuidesInterview Prep

Quick Overview

This question evaluates proficiency in JavaScript data manipulation and asynchronous programming, testing competencies in transforming nested objects into single-level key paths and reproducing Promise.all semantics.

  • medium
  • TikTok
  • Coding & Algorithms
  • Software Engineer

Flatten object & Promise.all

Company: TikTok

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

##### Question Given a nested JavaScript object, write a function to flatten it so that nested keys are converted to a single-level path (e.g., {a:{b:1}} -> {'a.b':1}). Implement Promise.all from scratch in JavaScript; it should take an iterable of promises/values and return a single promise that resolves when all inputs resolve or rejects when any input rejects.

Quick Answer: This question evaluates proficiency in JavaScript data manipulation and asynchronous programming, testing competencies in transforming nested objects into single-level key paths and reproducing Promise.all semantics.

Given a nested dictionary obj whose values may be dictionaries or lists (both possibly nested), return a new flat dictionary mapping dot-separated paths to leaf values. Build paths by concatenating dictionary keys and list indices with a dot. Only values that are neither dictionaries nor lists are emitted as leaves. Do not create entries for empty dictionaries or empty lists. Assume all dictionary keys are strings that do not contain a dot. Do not mutate the input.

Constraints

  • 1 <= total number of dictionary entries + list items <= 100000
  • Maximum nesting depth <= 500
  • All dictionary keys are strings without '.'
  • Leaf values can be int, float, str, bool, or None
  • Input must not be mutated

Hints

  1. Use DFS to traverse the structure and build the path as you go.
  2. Maintain a list of path segments and join with '.' when you reach a leaf.
  3. Treat dictionaries and lists separately; skip empty ones.
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)