-
Notifications
You must be signed in to change notification settings - Fork 54
/
Question5.txt
32 lines (29 loc) · 2.36 KB
/
Question5.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Question 5
Write a function to return an array containing all elements common to two
given arrays containing distinct positive integers. You should not use any inbuilt
methods. You are allowed to use any number of arrays.
The signature of the function is:
int[] f(int[] first, int[] second)
Examples:
--------------------------------|--------------------------------------------------------------
| if the input parameters are | return |
|--------------------------------|--------------------------------------------------------------|
| {1,8,3,2},{4,2,6,1} | {1,2} |
|--------------------------------|--------------------------------------------------------------|
| {1,8,3,2,6},{2,6,1} | {2,6,1} |
|--------------------------------|--------------------------------------------------------------|
| {1,3,7,9},{7,1,9,3} | {1,3,7,9} |
|--------------------------------|--------------------------------------------------------------|
| {1,2}, {3,4} | {} |
|--------------------------------|--------------------------------------------------------------|
| {}, {1,2,3} | {} |
|--------------------------------|--------------------------------------------------------------|
| {1,2}, {} | {} |
|--------------------------------|--------------------------------------------------------------|
| {1,2}, null | null |
|--------------------------------|--------------------------------------------------------------|
| null, {} | null |
|--------------------------------|--------------------------------------------------------------|
| null, null | null |
--------------------------------|--------------------------------------------------------------
NOTE: To ease debugging, Will return a string array.