PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Zillow

Implement placeholder-based pattern matcher

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's ability to implement linear-time string parsing and placeholder substitution with dictionary lookups, including robust error reporting for missing keys.

  • medium
  • Zillow
  • Coding & Algorithms
  • Machine Learning Engineer

Implement placeholder-based pattern matcher

Company: Zillow

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given: 1. A string `s` that may contain **placeholders** delimited by the `%` character. 2. A dictionary `dict` mapping keys (strings) to replacement values (strings). A **placeholder** is any substring that starts and ends with `%`, for example `%key%`. The text between the two `%` characters (here, `key`) is used as a lookup key in `dict`. Example: - `s = "a%sd%fasd%dog%sdfisan"` - `dict = { "sd": "HELLO", "dog": "CAT" }` Expected output: - `"aHELLOfasdCATsdfisan"` ### Rules - Parse `s` from left to right. - Text outside of `%...%` is copied directly to the output. - When you encounter a `%`, you start reading a key until the next `%`: - The characters between the two `%` characters form the key. - Look up this key in `dict`. - If the key exists, append `dict[key]` to the output. - If the key does **not** exist in `dict`, the function should report an **error** (for example, by returning a special error value or throwing an exception; define your choice clearly in your solution). - You may assume that `%` characters are properly paired (no unmatched `%`). - There is no escaping mechanism for `%` (every `%` starts or ends a placeholder). ### Task - Implement a function that performs this substitution according to the rules above. - Clearly specify: - The function signature in the programming language of your choice. - How errors are represented/returned when a key is missing from `dict`. - Aim for a solution that runs in linear time in the length of `s` (plus the cost of dictionary lookups).

Quick Answer: This question evaluates a candidate's ability to implement linear-time string parsing and placeholder substitution with dictionary lookups, including robust error reporting for missing keys.

Related Interview Questions

  • Write pseudocode for a ReAct-style loop - Zillow (medium)
  • Implement k-th largest in a number stream - Zillow (medium)
  • Find max min-plus-max over all subarrays - Zillow (medium)
Zillow logo
Zillow
Jul 18, 2025, 12:00 AM
Machine Learning Engineer
Technical Screen
Coding & Algorithms
1
0

You are given:

  1. A string s that may contain placeholders delimited by the % character.
  2. A dictionary dict mapping keys (strings) to replacement values (strings).

A placeholder is any substring that starts and ends with %, for example %key%. The text between the two % characters (here, key) is used as a lookup key in dict.

Example:

  • s = "a%sd%fasd%dog%sdfisan"
  • dict = { "sd": "HELLO", "dog": "CAT" }

Expected output:

  • "aHELLOfasdCATsdfisan"

Rules

  • Parse s from left to right.
  • Text outside of %...% is copied directly to the output.
  • When you encounter a % , you start reading a key until the next % :
    • The characters between the two % characters form the key.
    • Look up this key in dict .
    • If the key exists, append dict[key] to the output.
    • If the key does not exist in dict , the function should report an error (for example, by returning a special error value or throwing an exception; define your choice clearly in your solution).
  • You may assume that % characters are properly paired (no unmatched % ).
  • There is no escaping mechanism for % (every % starts or ends a placeholder).

Task

  • Implement a function that performs this substitution according to the rules above.
  • Clearly specify:
    • The function signature in the programming language of your choice.
    • How errors are represented/returned when a key is missing from dict .
  • Aim for a solution that runs in linear time in the length of s (plus the cost of dictionary lookups).

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Zillow•More Machine Learning Engineer•Zillow Machine Learning Engineer•Zillow Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ 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
  • Compare Platforms
  • Discord Community

Support

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

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.