Trace Pointer Rebinding and Pointee Updates
Problem statement
A function receives a pointer to a caller-owned integer by value. Process each operation in order:
WRITE:xwritesxthrough the function's current pointer.REBIND:xchanges only the function's local pointer copy so it points to a local integer whose value isx.
Once rebound, later writes affect the local integer rather than the caller-owned integer. Return the caller-owned value after the function returns.
Function
callerValueAfter(initialValue: int, operations: String[]) → intExamples
Example 1
initialValue = 10operations = ["REBIND:100"]return = 10Rebinding changes only the local pointer copy, so the caller still observes 10.
Example 2
initialValue = 10operations = ["WRITE:100"]return = 100Writing through the original pointer updates the caller-owned integer.
Constraints
-1000000000 <= initialValue <= 1000000000.0 <= operations.length <= 100000.- Every operation is
WRITE:xorREBIND:x, wherexis a signed 32-bit integer.
Source note: Author-written prompt excerpt retained for source fidelity.