Predict Runtime Method Dispatch
Problem statement
A base type defines label() as base, and a derived type overrides it as derived. Each entry in runtimeTypes is B or D and is stored behind a base-typed reference.
Return the output of calling label() for every object in order. Calls use runtime dispatch.
Function
dispatchLabels(runtimeTypes: String[]) → String[]Examples
Example 1
runtimeTypes = ["B","D","D"]return = ["base","derived","derived"]The runtime object decides which override runs.
Example 2
runtimeTypes = []return = []No calls produce no output.
Constraints
0 <= runtimeTypes.length <= 100000.- Every entry is
BorD.
Source note: Author-written prompt excerpt retained for source fidelity.