Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranî)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
All right.
So now let's try to solve this exercise, then we will do the following.
We will say that that will be our array of elements.
I don't know why we use the size of 10, but let's simply stick with it.
OK, so that will be the array that we are going to use.
We will specified as inputs and what we are going to do.
These basically to write a program that should count that to count the number of unique elements.
And also, we should print all the unique elements in the process.
So the final result that we expect to see of this program is basically something like this, OK?
So let's say this will be the console output console output.
So what we expect to see is basically we can see from here, right, we can see that.
Let's say, let's take this nice color, OK, so we can see that five and five.
That's something that appears more than once, meaning it's not unique.
Seven appears just once.
Three appears more than once.
Right here it is.
Four appears once six, eight, nine and 10.
So what we expect to see is that unique numbers are unique numbers.
Our seven, four, six eight, eight eight, what was it, eight, eight, nine in 10 and total unique
numbers?
What should be printed here?
Total unique numbers.
What should be printed?
One two three four five six six total numbers.
Okay.
So that's the answer that we.
Aim or help.
That we will be able to see.
And now the question comes to how can we achieve it?
OK, that's what we are going to explore right now.
That's what you were requested to do.
OK, so if at any point in my solution, you think that, oh, you found the answer in, you know,
how to do it so you can pause this video and basically to continue it once you try to solve it on your
own again.
So that's also just fine.
So what is the main objective?
What is the main goal?
How can we know if any value is unique?
And please, guys, just to make sure this question.
It has a lot of different approaches.
Some of them are faster and optimized than some of them are not.
And so in this lecture, we are not talking and we are not concerned about optimization and improving
the the run time and so on and so forth.
Then I will go just with the basic approach to make sure that it works OK.
And for those of you who want to a little bit improve the performance, you can suggest more sophisticated
approaches.
But for now, that should be just enough.
OK, so what I suggest is do the following OK, that would be the solution that I suggest we will take
every value right here.
OK?
And what we will do is we will compare this value with any of the other values inside of this array.
If we will find at least one element that equals to this one, then it means definitely that this value
is not unique and we should not print it, and we should not also add it to our counter of number of
unique elements.
And we will repeat this process over and over again for all of the elements of this array, and we will
check them right.
We will check them with this one, with this one.
With this one.
And with this one, right?
With everybody.
And that's the way we are going to use to find the total number of unique elements.
So let's say here will be the part of the input.
OK, so here we will create input array.
OK, we will receive values from the user.
We created an array of, say, stand off integers.
We will read these values from the user.
And then what we are going to do is we are going to iterate over all of these elements, how we are
going to do it.
First of all, you will need additional variable.
We will call it count unique or unique, unique count.
We will set it up to be equal to zero.
And every time that we will make sure that a certain value is unique in an array, we will incremented
by one.
All right.
So now what we need to do is to start thinking about, OK, how we can iterate over all of these elements.
So we will go like this for I equals to zero ice less than 10 in this case and I + +.
Right.
So far, so good.
Now what we will need to do is basically OK to think about want and basically what should be the approach
for accessing all of these other elements.
So to access all of the other elements, we will need maybe some index, right, I represents the current
index that we are using and Jay will be used to represent any of the other elements.
OK, so I will be here.
And Jay will be an index that runs from, let's say g equals to one g equals to two g equals to three
and so on and so forth.
Right.
So we will compare with a specific I whenever I equals two, let's say zero.
We will compare it with J equals to one.
Jake will stick to Jake or two, three and so on and so forth.
And then, for example, whenever we reach this element, we will say I equals two two.
We will start j from zero and we will compare.
If value is index, I equals two values at Index J.
Then we know that these values is not unique.
And if it does not equal to it, then it's not necessarily means that these value three is not unique.
We will need to move j to the next element, right?
We will need to move J right here and ask the following question again and again and again.
OK, so that's the main concept of working, what we will need also to take into account is that these
J.
May also come here and we do not want to compare this value to itself because we know that if we compare
a value to itself, it will always be the same value.
So we will need to make sure that inside of the iterations that we do, we check and make sure that
I does not equal to Jane.
All right.
So how would we look like in code?
OK, once.
I hope that once their theory is clear to you, we'll take a look at the actual code.
So here we will create additional index will create Index G.
And we will iterate over all of these elements for a j equals to zero as long as JS less than 10.
J Les Plus.
And now here inside of these for a loop, right, because we use nested loops in this case, we ask
the following question if.
If what if I equals to J.
Then there is no need to check this out and we can continue, right, we can continue for the next iteration
inside of these new inner for a loop.
So we fi equals the J continue to the next for a loop and increment j by one.
That's also fine.
Awesome.
But if it if they are not equal, what should we ask?
So we can ask if?
If values at index, i.e. equal to values at Index J.
Then what we can see.
What can we say about it?
Can we say that?
That's absolutely not unique.
Yes, we can.
So if it's not unique, what should we do?
Should we break?
Right, I mean, should we break from this program?
Can we just break here?
Yes, that's one option, but we break it from this loop.
So we finished basically executing all of the lines of code here.
So how can we know once we have finished executing the inner for a loop, how can we know right here
at this point in time?
How can we know if we found a duplicate or not?
Well, that can be kind of tricky.
OK, but what I recommend?
Because why can it be tricky?
Because if the last element does not equal to two value sitting design, let's say equals to nine?
And you do not know if you.
Yeah, basically.
Yeah, basically, we can't even do it without additional variable.
We can ask a simple question if J.
If J equals to 10, right?
If Jake was 10, because it means that we have iterated over all of the elements right here and we did
not find four.
Amy J.
We did not find that this condition was satisfied.
Then we reached the J equals to 10, and the condition right here was not satisfied and we moved on.
That means that we did not.
Find any.
Duplicate value or value, is that index, say then in this case, what we can do is basically, say
the following.
If that's the case, let's print f the value set index say OK.
Unique value and here print percentage.
And here, print something like that, OK, so let's go.
Print.
I don't know what values at index, I write.
Thing that's correct, yeah.
And also, we can do count what where was it unit count?
What was it?
Yeah, unit count plus plus.
So is it clear what do we do here?
So we ask if Jake will stay 10, then it means that we not find any duplicate value, then print unique
value and also unique count.
And now they're approached to do this, OK is create additional variable and call it, I don't know,
into found duplicate.
Duplicate equals to zero.
OK, and this will say that we need not found a duplicate and we will say if we did find a duplicate,
that's another approach we can say.
We can say found duplicate equals to one right?
And then here we can ask if.
Found duplicate does not equal to one, meaning we did not find duplicate for this value, right?
Then printf and unique count plus plus and finally, before the beginning of the next iteration set
found duplicate equal to zero and then increment the itself.
OK, so let's try to run it and see what happens and if it works correctly and exactly as we expected
it to work.
Let's go like this.
OK, so let's use the values that we have here.
So five seven three four five, six, eight, nine, 10 and three so unique values.
Seven.
Here it is.
Four, six, eight, nine and 10.
Awesome.
So all the unique values seemed to be found in this example.
Great.
Now finally, what we need to do is also to print total unique numbers.
So they asked what was missing.
So we are going to print.
Total.
Total.
Unique numbers, and we are going to print it out to the screen.
And that should be the unique count.
That's it.
All right.
So once again, what's happening here is that we start, Okay, I'm going to show you one or two iterations
to make it clear to you.
So we start with this outer loop with start with equals to zero.
And in the inner loop, we start that e j equals to zero.
So we start with here, I and J both here we ask if I equals to J.
Yes.
So continued through the next iteration.
Seth J.
To be equal to one.
So now J equals two one.
We ask if values at Index I, which is one which is index zero, equals two values at Index J.
If yes, then simply set found duplicate equal to one.
And also, you can just break from here, OK?
To save it from additional.
What is it to save it from additional, unnecessary checking?
OK.
So if you found a duplicate, there is.
There is no reason to continue.
This for a loop.
OK, so if you found it awesome, if not, let's basically move on again to these for a loop.
Now Jay will be equal to two.
Right.
If it is equal, then awesome, if not, let's move to the G equals to three.
Now, Jay, here and then Jay here, right, Jay equals two four.
And now we found out that values hitting Dixie whenever I equals two zero equals devalues value index
J one J equals two for.
In this case, what we do is we set these flag found duplicate equal to one and we break break from
where break from this inner loop and we go right here.
So we ask, we found duplicate does not equal to one, then what we that's what we do otherwise.
OK, let's go.
Found duplicate equals to zero and then we start again.
So in this case, we can also improve it a little bit because there is actually no reason to set it
here.
We can also do this operation right here because otherwise it will always be zero as well, but it would
work the same way.
And yeah, then you stop and you move on and increment I by one, meaning you move on.
To the next value that you are going to check, J comes back to be equal to zero.
So that's I, and that's Jay.
And then you go again, you compare seven and five and then you ask, that's the same sum.
Do not compare it.
Then you compare seven and three and so on and so forth.
OK.
So I hope that's clear.
Guys, let's make the final is execution for this exercise and use here.
What was it?
Five seven three four five six eight, nine, 10 and three and total unique numbers is zero, but nothing
was printed.
What was wrong?
What was wrong, what what did we do wrong here?
One second found duplicate break.
Oh, I'm.
But I think, you know, what was it one second?
Oh, yes, sorry about that.
So, yeah, that was the problem, we should not be here, obviously, because we only reach this place
when found on duplicate equal to zero, so it definitely should be here.
And maybe you should also be under the L section.
So that's also a good option for it to be.
OK, but now it should work.
OK, so that was yeah, I guess we problem that was fixed immediately.
So let's make sure now it works.
Hopefully, bugs are always something that we should expect, but hope not.
See, but yeah, that's basically what happens.
So, yeah, so here it is, unique values and there it is totally unique names.
So I hope everything is clear, guys.
Let me know if you have any questions, feel free to ask whatever it is.
And also, please feel free to leave some feedback and review.
It helps me a lot in creating these content.
It helps me also to improve it.
And it's really nice to see your feedback once in a while.
So thank you guys for watching.
My name is Vlad of Lisa's Alpha Tech and I wish you a great day by.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.