This challenge is to see how applicants understand requirements and implement a nice solution in nice code.
As a developer, you should be able to calculate the intersects
of two arrays (a1
, a2
) so that the following criterias are met:
- all elements, that occur in both arrays, are available in the resulting array.
- the resulting array should be sorted
Implement an intersect
method, without using the built in #intersect
method of the class Array
, that takes 2 arrays as arguments
a1 = [3,3,1,3]
and
a2 = [1,2,3,3]
and
returns [1,3]
.
Implement the intersect
method same as above, but elements commonly appearing multiple times in both arrays should be reflected in the result.
E.g.
a1 = [3,3,1,3]
and
a2 = [1,2,3,3]
and
returns [1,3,3]
(have a look at the digit 3
appearing twice in the result).
We want to understand how you approach the task and be able to follow, so speaking out your thoughts, helps us understand you better.
Please provide also considerations about e.g. performance, O-notation etc.