FastPrepApply Overridden Integer Transforms

Apply Overridden Integer Transforms

Optimus Information logoOptimus Information● EasyINTERNONSITE INTERVIEW
Learn

Problem statement

A base transformer returns x + 1. A derived transformer overrides the same method and returns x * x. For each value, kinds[i] is B or D and selects the runtime object behind a base reference.

Return every transformed value in order.

Function

applyTransforms(values: int[], kinds: String[]) → long[]

Examples

Example 1

values = [2,3,-4]kinds = ["B","D","D"]return = [3,9,16]

The base object increments while derived objects square.

Example 2

values = []kinds = []return = []

Empty input produces empty output.

Constraints

  • values.length == kinds.length.
  • 0 <= values.length <= 100000.
  • |values[i]| <= 1000000000.

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

More Optimus Information problems

See Optimus Information hiring insights
public long[] applyTransforms(int[] values, String[] kinds) {
    // Write your code here.
}
values[2,3,-4]
kinds["B","D","D"]
expected[3,9,16]
Checking account…