Having a hard time designing an efficient algorithm that accomplishes the following. If I start with a 2d vector A,

```
A = [1 2 3;
     2 3 4;
     5 6]

```

I want to take the rows that contain common elements and combine them (removing duplicates) resulting in 2d vector B:

```
B = [1 2 3 4;
     5 6] 

```

I can accomplish this in Matlab, but am having a hard time in C++. Any help is appreciated.