Loading...
Loading...
In COBOL, the LINKAGE SECTION is a special data division used to define parameters and return values that are passed between programs (e.g., a main program calling a subprogram). It acts as a shared memory interface — data is not stored in the subprogram itself, but instead references memory owned by the calling program.
Inspired by this concept, your task is to simulate a parameter-passing system between a "caller" and a "callee" program. You are given a list of memory slots owned by the caller. The callee receives a list of linkage mappings — pairs indicating which caller slots map to which callee parameter slots. The callee then applies a transformation to each of its parameter slots and the result is reflected back into the caller's memory.
Given:
callerMemory: an array of integers representing the caller's memory slots.linkage: a 2D array of pairs [callerIndex, calleeIndex] describing which caller slot maps to which callee parameter slot (0-indexed).transformation: an array of integers of length equal to the number of unique callee slots, where transformation[calleeIndex] is a multiplier applied to each callee slot.Simulate the linkage: multiply each mapped caller memory value by its corresponding transformation multiplier, and write the result back to the caller's memory at the original caller index.
Return the updated callerMemory array.
Input:
callerMemory — list of integerslinkage — list of [callerIndex, calleeIndex] pairstransformation — list of integers (multipliers indexed by callee slot)Output: Updated callerMemory array after applying all transformations via linkage.
callerMemory = [10, 20, 30]
linkage = [[0, 0], [2, 1]]
transformation = [3, 5]
Output: [30, 20, 150]
Explanation: Slot 0 of caller maps to callee slot 0 → 10 * 3 = 30. Slot 2 of caller maps to callee slot 1 → 30 * 5 = 150. Slot 1 has no linkage so remains 20.
callerMemory = [4, 8, 15, 16]
linkage = [[1, 0], [3, 1]]
transformation = [2, 4]
Output: [4, 16, 15, 64]
Explanation: Slot 1: 8 * 2 = 16. Slot 3: 16 * 4 = 64. Others unchanged.
callerMemory = [5]
linkage = [[0, 0]]
transformation = [10]
Output: [50]
Single slot: 5 * 10 = 50.
1 <= callerMemory.length <= 10^4 -10^4 <= callerMemory[i] <= 10^4 0 <= linkage.length <= callerMemory.length linkage[i] = [callerIndex, calleeIndex] where 0 <= callerIndex < callerMemory.length 0 <= calleeIndex < transformation.length 1 <= transformation.length <= 10^4 -100 <= transformation[i] <= 100 All callerIndex values in linkage are unique. All calleeIndex values in linkage are unique.
calleeIndex → multiplier using the transformation array.linkage pairs, apply the multiplier to callerMemory[callerIndex], and update in-place.