FastPrepEnvironment Variable Store and Substitution

Environment Variable Store and Substitution

Amazon logoAmazon● MediumFULLTIMEPHONE SCREEN

Problem statement

Process a sequence of environment-variable operations:

  • ["SET", key, value] stores or overwrites a value.
  • ["GET", key] emits the value or NULL when missing.
  • ["PARSE", text] emits text after replacing every complete %KEY% placeholder whose key exists. Missing placeholders remain unchanged.

Substitution is one pass: replacement values are not expanded again during the same operation.

Function

processEnvironment(operations: String[][]) → String[]

Examples

Example 1

operations = [["SET","NAME","Tom"],["PARSE","Hello I am %NAME%"]]return = ["Hello I am Tom"]

The stored NAME value replaces its placeholder.

Example 2

operations = [["GET","MISSING"],["PARSE","%MISSING%"]]return = ["NULL","%MISSING%"]

Missing GET and PARSE have distinct deterministic outputs.

Constraints

  • 1 <= operations.length <= 10^5.
  • Keys contain letters, digits, or underscores and are nonempty.
  • Each operation row has the required fields.

More Amazon problems

See Amazon hiring insights
Saved
public String[] processEnvironment(String[][] operations) {
  // write your code here
}
Checking account…