FastPrepTrace Pointer Rebinding and Pointee Updates

Trace Pointer Rebinding and Pointee Updates

Arista Networks logoArista Networks● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

A function receives a pointer to a caller-owned integer by value. Process each operation in order:

  • WRITE:x writes x through the function's current pointer.
  • REBIND:x changes only the function's local pointer copy so it points to a local integer whose value is x.

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[]) → int

Examples

Example 1

initialValue = 10operations = ["REBIND:100"]return = 10

Rebinding changes only the local pointer copy, so the caller still observes 10.

Example 2

initialValue = 10operations = ["WRITE:100"]return = 100

Writing through the original pointer updates the caller-owned integer.

Constraints

  • -1000000000 <= initialValue <= 1000000000.
  • 0 <= operations.length <= 100000.
  • Every operation is WRITE:x or REBIND:x, where x is a signed 32-bit integer.

Source note: Author-written prompt excerpt retained for source fidelity.

More Arista Networks problems

See Arista Networks hiring insights
public int callerValueAfter(int initialValue, String[] operations) {
    // Write your code here.
}
initialValue10
operations["REBIND:100"]
expected10
Checking account…