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.
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:
"%X% and %Z%"
"a and a and b"
Assumptions/requirements to clarify in your solution:
A -> "%B%"
,
B -> "%A%"
).