FastPrepDispatch Virtual Shipping Prices

Dispatch Virtual Shipping Prices

Optimus Information logoOptimus Information● EasyINTERNONSITE INTERVIEW
Learn

Problem statement

A standard pricing object computes 2 * weight. An express pricing object overrides the virtual method and computes 3 * weight + 5. For each shipment, service[i] is S or E.

Invoke the selected object through the shared interface and return all prices.

Function

shippingPrices(weights: int[], service: String[]) → long[]

Examples

Example 1

weights = [4,4,10]service = ["S","E","S"]return = [8,17,20]

Each call dispatches to the runtime pricing object.

Example 2

weights = []service = []return = []

No shipments produce no prices.

Constraints

  • weights.length == service.length.
  • 0 <= weights.length <= 100000.
  • 0 <= weights[i] <= 1000000000.

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

More Optimus Information problems

See Optimus Information hiring insights
public long[] shippingPrices(int[] weights, String[] service) {
    // Write your code here.
}
weights[4,4,10]
service["S","E","S"]
expected[8,17,20]
Checking account…