1. ## help plz-begginer question

Function returns the maximum size of the common between the two arrays?
(function recieve (array a, length of a , array b, length of b ))

for ex:
array a{2,1,2,3}
array b{2,3}
the res would be 2.{2,3 shown in array a and its the max

array a{2,2,2}
array b{2}
the res would be 1.

array a{2,1,2,3}
array b{3,4,5}
the res would be 1.

array a{4,5,2,1,2,3}
array b{9,8,8,7,8,8,2,3}
the res would be 2.

hope u understood the question

i am stuck i cant figured it out ..
i thought to run with two loops
Code:
```for (i=0; i<lenght of a; i++)
{
for (j=0; j<length of b; j++)
{
if(a[i]==b[j])
{
count++;```
and here i got stuck i can keep the count .. but then when it founds another nums that are equals i dont know how to split the counter from 0 and then to check what is the max .

thank u .. and i really tried for a couple of hours and the right solution dont hit me .

2. Sorry, the stupid vbulletin code catcher made me do this:
Code:
```

Originally Posted by erag

array a{4,5,2,1,2,3}
array b{9,8,8,7,8,8,2,3}
the res would be 1.

```
Looks to me like it would be 2 (2 and 3). Or do I not understand your question?

3. Count *is* the max - it's a quantity, and can't be greater than the number of values in the smaller of the arrays. you'll need to add that bit of code, and put it in place right after the two loops are completed.

I don't understand your comment about "split the counter from 0 and then to check what is the max".

Duplicate numbers will have to be handled so only 1 of them is sent down for the loops to work with. I'd suggest using a bucket sort type of arrangement (aka distribution count), to make sure each number going to the loops, is a unique number.

Alternatively, you could sort both arrays and use some logic to handle this, but that would be more work.

4. Also your only example of any match greater that 1 was for your 2 consecutive numbers. Are you not worried about matching elements that are split? Are you more after locating the longest match or just the first match found? I think there are some necessary points of your assignment missing here. In either case if you know how to loop through your arrays calculating for both and tallying up the results should be easy on any account.

5. hi guys thank u for the quick answer ..
slingerland3g : i am intersted in locating the longest match .
Adak :"I'd suggest using a bucket sort type" -i dont know what it is ..
and yes the duplacted ones are the ones who causes me trouble.
can you direct me by writing the code so i could understand it ?
i got lost and i know that is not to hard.
thnks.

6. somebody?

7. Originally Posted by erag
somebody?
Code:
```#include <stdio.h>
#define a_size 6
#define b_size 8
int function(int array_a[], int lenght_a, int array_b[], int lenght_b);
int main()
{
int a[a_size] = { 4, 5, 2, 1, 2, 3 };
int b[b_size] = { 9, 8, 8, 7, 8, 8, 2, 3 };

int result = function(a, a_size, b, b_size);
printf("%d\n", result);

return 0;
}
int function(int array_a[], int lenght_a, int array_b[], int lenght_b)
{
int i, j, count = 0, hold = 0;
for(i = 0; i < a_size; i++) {
for(j = 0; j < b_size; j++) {
if((array_b[j] == array_a[i])&&(array_b[j] != hold)) {
count++;
hold = array_b[j];
}
}
}
return count;
}```
This should work

8. thank u !!i'll check out all the case in a bit
but i noticed that if i send:
Code:
```a{0,0}
b{0}```
the res is 0 instead of 1
and in the question i need to return count .. but if the function didnt find nothing"count=0"
it should be "return (-1)"
how do i resolve it?

another case i just noticed
Code:
```int a[a_size] = { 2,4 };
int b[b_size] = { 2,3,4}}```
the func return "2" insteead of "1".

thanks again you really helped me...

9. Originally Posted by erag
thank u !!i'll check out all the case in a bit
but i noticed that if i send:
Code:
```a{0,0}
b{0}```
the res is 0 instead of 1
and in the question i need to return count .. but if the function didnt find nothing"count=0"
it should be "return (-1)"
how do i resolve it?

another case i just noticed
Code:
```int a[a_size] = { 2,4 };
int b[b_size] = { 2,3,4}}```
the func return "2" insteead of "1".

thanks again you really helped me...
that solves the first problem, about the second one why does it have to return 1?
Code:
```int function(int array_a[], int lenght_a, int array_b[], int lenght_b)
{
int i, j, count = 0, hold = -1;
for(i = 0; i < a_size; i++) {
for(j = 0; j < b_size; j++) {
if((array_b[j] == array_a[i])&&(array_b[j] != hold)) {
if(count == 0) {
hold = 0;
}
count++;
hold = array_b[j];
}
}
}
return count;
}```

10. cause the num 2 shows 1 time in array a. and num 4 is also showed 1 timein array a.

the two nums shows in array be one time each so the func shoulld return 1
the func check within the array a the max appearence and the max is 1.
1 for 2
1 for 4