Common elements P12675


Statement
 

pdf   zip   main.cc

html

Write a function

int common_elements(const vector<int>& X, const vector<int>& Y);

that given two vectors X and Y in increasing order, returns the number of common elements in the two vectors, that is, the number of integer numbers a such that a=X[i]=Y[j] for any i and j.

Precondition

The two vectors are in strictly increasing order.

Samples

common_elements([3,5,7,8], [2,3,7,9,10]) = 2.
common_elements([1,2,3,4,5], [3,4,5,6,7,8]) = 3.
common_elements([1,2,3,4,5], [8,9]) = 0.

Information
Author
Jordi Petit
Language
English
Translator
Carlos Molina
Original language
Catalan
Other languages
Catalan
Official solutions
C++
User solutions
C++