Write a tool which supports substitutions of templates by other strings.
Complete the function substituteTemplates in the editor.
substituteTemplates has the following parameters:
- 1.
Map: a map containing the substitutionssubstitutions - 2.
String template: the template string to be resolved
Returns
String: the resolved template
Examples
01 · Example 1
substitutions = {"X" -> "123", "Y" -> "456", "Z" -> "abc"}
template = "%X%_%Y%"
return = "123_456"The template
%X%_%Y% should be resolved by replacing %X% with 123 and %Y% with 456, resulting in 123_456.02 · Example 2
substitutions = {"X" -> "123", "Y" -> "456", "Z" -> "abc%Y%"}
template = "%X%_%Y%_%Z%"
return = "123_456_abc456"The template
%X%_%Y%_%Z% should be resolved by replacing %X% with 123, %Y% with 456, and %Z% with abc%Y% which further resolves to abc456. The final result is 123_456_abc456.More Google problems
- Periodic Table Word FormationsPHONE SCREEN · Seen Jun 2026
- Split and Sort ArraySeen Jun 2026
- Fountain SafetyONSITE INTERVIEW · Seen Jun 2026
- Consolidate On-Call RotationsOA · Seen Jun 2026
- Detonate Bombs with Chain ReactionsONSITE INTERVIEW · Seen May 2026
- Evaluate a Nested Math ExpressionONSITE INTERVIEW · Seen May 2026
- Tic-Tac-Toe Game StatusPHONE SCREEN · Seen May 2026
- Longest Dictionary TokenizationPHONE SCREEN · Seen May 2026
public String substituteTemplates(Map<String, String> substitutions, String template) {
// write your code here
}
substitutions{"X" -> "123", "Y" -> "456", "Z" -> "abc"}
template"%X%_%Y%"
expected"123_456"
checking account