FastPrepCompute Areas Through an Abstract Shape Type

Compute Areas Through an Abstract Shape Type

Optimus Information logoOptimus Information● EasyINTERNONSITE INTERVIEW
Learn

Problem statement

Implement an abstract shape contract with an area() operation. Each kind is SQUARE, RECTANGLE, or TRIANGLE. The parallel arrays first and second provide side/width/base and ignored/height/height respectively.

Return twice each shape's geometric area, avoiding fractions: square 2*a*a, rectangle 2*w*h, triangle b*h.

Function

twiceAreas(kinds: String[], first: int[], second: int[]) → long[]

Examples

Example 1

kinds = ["SQUARE","RECTANGLE","TRIANGLE"]first = [3,4,5]second = [0,6,7]return = [18,48,35]

Every concrete shape supplies the same abstract operation.

Example 2

kinds = []first = []second = []return = []

No shapes produce no areas.

Constraints

  • All three arrays have equal length at most 100000.
  • Dimensions are integers in [0, 1000000000].
  • second[i] is ignored for squares.

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

More Optimus Information problems

See Optimus Information hiring insights
public long[] twiceAreas(String[] kinds, int[] first, int[] second) {
    // Write your code here.
}
kinds["SQUARE","RECTANGLE","TRIANGLE"]
first[3,4,5]
second[0,6,7]
expected[18,48,35]
Checking account…