FastPrepPredict Runtime Method Dispatch

Predict Runtime Method Dispatch

AMD logoAMD● EasyFULLTIMEONSITE INTERVIEW
Learn

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 B or D.

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

More AMD problems

See AMD hiring insights
public String[] dispatchLabels(String[] runtimeTypes) {
    // Write your code here.
}
runtimeTypes["B","D","D"]
expected["base", "derived", "derived"]
Checking account…