PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This intermediate-level Coding & Algorithms problem for Data Scientist roles evaluates string parsing and manipulation skills along with dependency resolution techniques such as recursion or graph traversal, cycle detection, and memoization.

  • medium
  • Meta
  • Coding & Algorithms
  • Data Scientist

How do you expand nested placeholders in strings?

Company: Meta

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given a dictionary of string templates. Keys are identifiers like `X`, `Y`, `Z`. A template may contain placeholders of the form `%KEY%`, which should be replaced by the fully-expanded value of `KEY`. Example dictionary: - `X -> "a"` - `Y -> "b"` - `Z -> "%X% and %Y%"` Given an input string that may also contain placeholders (e.g., `"%X% and %Z%"`), return the fully expanded string. Example: - Input: `"%X% and %Z%"` - Output: `"a and a and b"` Assumptions/requirements to clarify in your solution: - Templates can reference other templates (nested expansion). - Decide how to handle missing keys and cyclic references (e.g., `A -> "%B%"`, `B -> "%A%"`). - Provide time/space complexity for your approach.

Quick Answer: This intermediate-level Coding & Algorithms problem for Data Scientist roles evaluates string parsing and manipulation skills along with dependency resolution techniques such as recursion or graph traversal, cycle detection, and memoization.

Expand %KEY% placeholders recursively. Missing keys stay unchanged; cycles become <CYCLE:key>.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: ({'X':'a','Y':'b','Z':'%X% and %Y%'}, '%X% and %Z%')

Expected Output: 'a and a and b'

Explanation: Prompt example.

Input: ({'A':'%B%','B':'%A%'}, '%A%')

Expected Output: '<CYCLE:A>'

Explanation: Cycle marker.

Input: ({'A':'x'}, '%A% %M%')

Expected Output: 'x %M%'

Explanation: Missing key preserved.

Hints

  1. Model object-style prompts as operation streams when needed.
  2. Handle empty and boundary cases before the main logic.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

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

Product

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

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

  • Find Shortest Unique Prefixes - Meta (medium)
  • Compute Exclusive Execution Times - Meta (medium)
  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)