All right.
Problem number four, we have Union of Numbers, we got the right the program, which take two lines
of numbers and outputs the union of the two lists, there should be no duplicates.
So in this case, we have the lists of numbers and we should essentially combine it, but also remove
any duplicates which exist.
Great.
So let's get started.
I've already written the inputs reading part because it's been repetitive.
We create any reader initialize a line splitter, three in space and on an assignment to array of strings.
There you also have stories of strings.
I could convert it to numbers, actually, but I figure that I need to death for this problem.
It will work regardless of whether the elements are strings or numbers.
Anyway, so now we can actually get started.
So let's first solve the problem by not caring about duplicate.
So let's just combine the two.
How can we combine them?
Well, in order to do that, we can just add all the honors from one of the arrays to the second one.
So what we can do is we can just add all the elements from elements to two elements one, or we can
create a ternary, which we can copy all the elements from both arrays to to that to operate.
So that's also a possibility.
But let's actually do that.
So let's create.
Variable Courts Union and it will be on the marketplace so we can visualize it like that.
It's a slice of strings and we'll just add all the elements from this array to the union and then do
the same for the second.
All right.
So we'll iterate through all the elements in elements one.
And then we add them by using the pent up then to this union place, the current and all right, and
we just do the same for a limited second slice.
And Indians print the union, and this time we can actually use strings going.
Union going on with that space.
OK, we can do that because this is our slice of strength instead of a slice of other data types.
So this is convenient.
Let's run this.
So we have the silence.
I'll just copy them and phase them in and we'll get this resolved, but modest.
Although this is truly the combined result of both of these race.
We do have duplicates is that we have five, which is also present here, and we have eight, which
is also present here 14 as well.
So now we have to factor in whether there are any duplicates in these stories in order to do that.
We came out here check where we said if the element already exists.
OK, so one thing you can try is you can try searching for slides, complaints, elements going if there's
any built in function for that.
But unfortunately you find there isn't and you can create one.
So you can use this function if you don't know about functions, you have to.
Go without it, but if you know about them, you can copy that.
Use it, I won't use that now because it's not just another stretch problem.
If you don't know about solutions and you don't know what I just mentioned so far, you learn about
that in the next election.
Now I'll show you how to do it without anything extra, without thinking you or not.
OK, so let's check in the Olympics.
So will I.
In order to do that, we'll pay the variable.
Richard William and we'll check whether the Olympics is by default.
It will be false here.
Where will?
That if it's actually.
And in the end, we use it to say, if the element doesn't exist, we will add it to this slice, if
it does exist, we'll skip it and not do anything.
Now the next thing is to check it.
Yeah, I mean, this is how do we do that?
Well, we can go through each element of the union and check whether there is any element in that which
is equal to the current one.
So let's go ahead and do that.
We have another four wrench, although now the variable we'll call, that's co-eds.
Other.
We range over the unions, and here we check if the current government is equal to other than.
This exists variable, as he calls it, through, and at that point, we no longer have to go through
the rest of the cycle so we can break OK and we can do the same thing.
Or the other.
All right.
Nothing will actually be changed here because the variable name is the same.
And there you go, that's actually our program, let me try running it.
Let me input the same numbers again, and this time we get only six numbers and they're all unique.
OK, so that's how this works.
I think this is it's obvious how this works.
If not, you can actually let me give you a chance.
If you don't understand this, try running with the debugger yourself and see what's going on.
So this is just the I won't do it myself so that you get a chance to learn how to debug these programs
and understand them yourself without me having to help.
All right, so good luck with that.
And that was problem number four.