Compute Areas Through an Abstract Shape Type
Updated
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 Onsite Interview questions
Similar questions at other companies
- Ring Buffer OperationsAmazon · ONSITE INTERVIEW
- Recent Hit CounterAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
- Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
- Path Leaf Character IteratorGoogle · ONSITE INTERVIEWGoogle interview questions
- Randomized Collection with Duplicate ValuesOkta · ONSITE INTERVIEWOkta interview questions
- Escape Room LeaderboardPinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions
- Implement MallocNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
- Removal PoolCitadel · ONSITE INTERVIEWCitadel interview questions
- Circuit Breaker State MachineWise · ONSITE INTERVIEW
- Hybrid Run-Length and Bit-Packing EncoderDatabricks · ONSITE INTERVIEWDatabricks interview questions