Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,370 --> 00:00:02,270
All right.
2
00:00:02,360 --> 00:00:07,190
So now let's try to solve this exercise, then we will do the following.
3
00:00:07,460 --> 00:00:11,300
We will say that that will be our array of elements.
4
00:00:11,810 --> 00:00:15,410
I don't know why we use the size of 10, but let's simply stick with it.
5
00:00:15,590 --> 00:00:18,800
OK, so that will be the array that we are going to use.
6
00:00:19,160 --> 00:00:22,940
We will specified as inputs and what we are going to do.
7
00:00:22,970 --> 00:00:30,170
These basically to write a program that should count that to count the number of unique elements.
8
00:00:30,410 --> 00:00:33,500
And also, we should print all the unique elements in the process.
9
00:00:34,040 --> 00:00:40,330
So the final result that we expect to see of this program is basically something like this, OK?
10
00:00:40,400 --> 00:00:45,140
So let's say this will be the console output console output.
11
00:00:47,180 --> 00:00:51,920
So what we expect to see is basically we can see from here, right, we can see that.
12
00:00:52,550 --> 00:00:58,580
Let's say, let's take this nice color, OK, so we can see that five and five.
13
00:00:58,940 --> 00:01:03,470
That's something that appears more than once, meaning it's not unique.
14
00:01:04,040 --> 00:01:06,200
Seven appears just once.
15
00:01:06,680 --> 00:01:08,750
Three appears more than once.
16
00:01:09,020 --> 00:01:09,920
Right here it is.
17
00:01:10,220 --> 00:01:14,330
Four appears once six, eight, nine and 10.
18
00:01:14,780 --> 00:01:20,720
So what we expect to see is that unique numbers are unique numbers.
19
00:01:22,950 --> 00:01:34,740
Our seven, four, six eight, eight eight, what was it, eight, eight, nine in 10 and total unique
20
00:01:34,740 --> 00:01:35,400
numbers?
21
00:01:35,610 --> 00:01:36,960
What should be printed here?
22
00:01:37,440 --> 00:01:38,850
Total unique numbers.
23
00:01:39,210 --> 00:01:40,170
What should be printed?
24
00:01:40,650 --> 00:01:44,130
One two three four five six six total numbers.
25
00:01:44,610 --> 00:01:44,820
Okay.
26
00:01:44,820 --> 00:01:46,320
So that's the answer that we.
27
00:01:47,180 --> 00:01:48,290
Aim or help.
28
00:01:48,980 --> 00:01:51,110
That we will be able to see.
29
00:01:51,380 --> 00:01:54,710
And now the question comes to how can we achieve it?
30
00:01:55,220 --> 00:01:57,470
OK, that's what we are going to explore right now.
31
00:01:57,950 --> 00:01:59,900
That's what you were requested to do.
32
00:02:00,290 --> 00:02:06,200
OK, so if at any point in my solution, you think that, oh, you found the answer in, you know,
33
00:02:06,200 --> 00:02:14,720
how to do it so you can pause this video and basically to continue it once you try to solve it on your
34
00:02:14,720 --> 00:02:15,410
own again.
35
00:02:15,500 --> 00:02:16,970
So that's also just fine.
36
00:02:17,960 --> 00:02:20,020
So what is the main objective?
37
00:02:20,030 --> 00:02:21,010
What is the main goal?
38
00:02:21,020 --> 00:02:23,540
How can we know if any value is unique?
39
00:02:24,080 --> 00:02:28,470
And please, guys, just to make sure this question.
40
00:02:28,490 --> 00:02:31,340
It has a lot of different approaches.
41
00:02:31,490 --> 00:02:36,230
Some of them are faster and optimized than some of them are not.
42
00:02:36,590 --> 00:02:43,760
And so in this lecture, we are not talking and we are not concerned about optimization and improving
43
00:02:43,760 --> 00:02:46,250
the the run time and so on and so forth.
44
00:02:46,910 --> 00:02:52,910
Then I will go just with the basic approach to make sure that it works OK.
45
00:02:52,910 --> 00:03:00,680
And for those of you who want to a little bit improve the performance, you can suggest more sophisticated
46
00:03:00,680 --> 00:03:01,250
approaches.
47
00:03:01,250 --> 00:03:02,910
But for now, that should be just enough.
48
00:03:02,930 --> 00:03:10,220
OK, so what I suggest is do the following OK, that would be the solution that I suggest we will take
49
00:03:10,220 --> 00:03:12,350
every value right here.
50
00:03:12,800 --> 00:03:13,220
OK?
51
00:03:14,180 --> 00:03:22,100
And what we will do is we will compare this value with any of the other values inside of this array.
52
00:03:23,420 --> 00:03:33,020
If we will find at least one element that equals to this one, then it means definitely that this value
53
00:03:33,020 --> 00:03:40,340
is not unique and we should not print it, and we should not also add it to our counter of number of
54
00:03:40,340 --> 00:03:41,420
unique elements.
55
00:03:42,050 --> 00:03:48,170
And we will repeat this process over and over again for all of the elements of this array, and we will
56
00:03:48,170 --> 00:03:49,640
check them right.
57
00:03:49,640 --> 00:03:52,670
We will check them with this one, with this one.
58
00:03:52,910 --> 00:03:53,960
With this one.
59
00:03:54,020 --> 00:03:55,550
And with this one, right?
60
00:03:55,550 --> 00:03:56,600
With everybody.
61
00:03:56,870 --> 00:04:03,260
And that's the way we are going to use to find the total number of unique elements.
62
00:04:03,890 --> 00:04:06,350
So let's say here will be the part of the input.
63
00:04:06,470 --> 00:04:09,680
OK, so here we will create input array.
64
00:04:10,280 --> 00:04:12,590
OK, we will receive values from the user.
65
00:04:12,590 --> 00:04:15,050
We created an array of, say, stand off integers.
66
00:04:15,440 --> 00:04:17,420
We will read these values from the user.
67
00:04:17,690 --> 00:04:24,560
And then what we are going to do is we are going to iterate over all of these elements, how we are
68
00:04:24,560 --> 00:04:25,340
going to do it.
69
00:04:25,790 --> 00:04:28,010
First of all, you will need additional variable.
70
00:04:28,010 --> 00:04:34,550
We will call it count unique or unique, unique count.
71
00:04:35,360 --> 00:04:37,700
We will set it up to be equal to zero.
72
00:04:37,700 --> 00:04:43,400
And every time that we will make sure that a certain value is unique in an array, we will incremented
73
00:04:43,400 --> 00:04:44,000
by one.
74
00:04:45,190 --> 00:04:45,690
All right.
75
00:04:46,240 --> 00:04:52,630
So now what we need to do is to start thinking about, OK, how we can iterate over all of these elements.
76
00:04:53,380 --> 00:04:59,800
So we will go like this for I equals to zero ice less than 10 in this case and I + +.
77
00:05:00,340 --> 00:05:00,700
Right.
78
00:05:01,030 --> 00:05:01,960
So far, so good.
79
00:05:03,190 --> 00:05:11,740
Now what we will need to do is basically OK to think about want and basically what should be the approach
80
00:05:11,740 --> 00:05:14,170
for accessing all of these other elements.
81
00:05:15,460 --> 00:05:22,540
So to access all of the other elements, we will need maybe some index, right, I represents the current
82
00:05:22,540 --> 00:05:29,770
index that we are using and Jay will be used to represent any of the other elements.
83
00:05:29,800 --> 00:05:32,320
OK, so I will be here.
84
00:05:32,650 --> 00:05:40,120
And Jay will be an index that runs from, let's say g equals to one g equals to two g equals to three
85
00:05:40,120 --> 00:05:41,230
and so on and so forth.
86
00:05:41,260 --> 00:05:41,590
Right.
87
00:05:42,130 --> 00:05:47,290
So we will compare with a specific I whenever I equals two, let's say zero.
88
00:05:47,590 --> 00:05:50,260
We will compare it with J equals to one.
89
00:05:50,500 --> 00:05:53,980
Jake will stick to Jake or two, three and so on and so forth.
90
00:05:54,790 --> 00:05:59,460
And then, for example, whenever we reach this element, we will say I equals two two.
91
00:05:59,890 --> 00:06:03,700
We will start j from zero and we will compare.
92
00:06:04,000 --> 00:06:09,670
If value is index, I equals two values at Index J.
93
00:06:09,970 --> 00:06:12,520
Then we know that these values is not unique.
94
00:06:12,880 --> 00:06:20,020
And if it does not equal to it, then it's not necessarily means that these value three is not unique.
95
00:06:20,260 --> 00:06:23,830
We will need to move j to the next element, right?
96
00:06:23,840 --> 00:06:28,330
We will need to move J right here and ask the following question again and again and again.
97
00:06:30,090 --> 00:06:35,970
OK, so that's the main concept of working, what we will need also to take into account is that these
98
00:06:35,970 --> 00:06:36,450
J.
99
00:06:36,720 --> 00:06:43,290
May also come here and we do not want to compare this value to itself because we know that if we compare
100
00:06:43,350 --> 00:06:46,860
a value to itself, it will always be the same value.
101
00:06:47,430 --> 00:06:53,520
So we will need to make sure that inside of the iterations that we do, we check and make sure that
102
00:06:53,520 --> 00:06:55,590
I does not equal to Jane.
103
00:06:56,490 --> 00:06:56,940
All right.
104
00:06:57,810 --> 00:06:59,940
So how would we look like in code?
105
00:07:00,090 --> 00:07:00,900
OK, once.
106
00:07:00,930 --> 00:07:06,180
I hope that once their theory is clear to you, we'll take a look at the actual code.
107
00:07:06,900 --> 00:07:11,520
So here we will create additional index will create Index G.
108
00:07:12,890 --> 00:07:20,000
And we will iterate over all of these elements for a j equals to zero as long as JS less than 10.
109
00:07:22,060 --> 00:07:22,870
J Les Plus.
110
00:07:24,120 --> 00:07:30,630
And now here inside of these for a loop, right, because we use nested loops in this case, we ask
111
00:07:30,630 --> 00:07:32,280
the following question if.
112
00:07:33,640 --> 00:07:36,340
If what if I equals to J.
113
00:07:36,400 --> 00:07:43,810
Then there is no need to check this out and we can continue, right, we can continue for the next iteration
114
00:07:43,810 --> 00:07:47,640
inside of these new inner for a loop.
115
00:07:48,490 --> 00:07:53,170
So we fi equals the J continue to the next for a loop and increment j by one.
116
00:07:53,770 --> 00:07:54,640
That's also fine.
117
00:07:55,330 --> 00:07:55,810
Awesome.
118
00:07:57,270 --> 00:08:00,510
But if it if they are not equal, what should we ask?
119
00:08:00,870 --> 00:08:02,400
So we can ask if?
120
00:08:03,650 --> 00:08:10,550
If values at index, i.e. equal to values at Index J.
121
00:08:11,750 --> 00:08:12,800
Then what we can see.
122
00:08:13,880 --> 00:08:15,260
What can we say about it?
123
00:08:15,890 --> 00:08:17,090
Can we say that?
124
00:08:17,840 --> 00:08:19,850
That's absolutely not unique.
125
00:08:20,360 --> 00:08:21,590
Yes, we can.
126
00:08:22,220 --> 00:08:24,200
So if it's not unique, what should we do?
127
00:08:24,980 --> 00:08:26,060
Should we break?
128
00:08:27,210 --> 00:08:30,090
Right, I mean, should we break from this program?
129
00:08:30,540 --> 00:08:31,650
Can we just break here?
130
00:08:32,490 --> 00:08:37,830
Yes, that's one option, but we break it from this loop.
131
00:08:37,830 --> 00:08:42,750
So we finished basically executing all of the lines of code here.
132
00:08:44,120 --> 00:08:51,740
So how can we know once we have finished executing the inner for a loop, how can we know right here
133
00:08:51,740 --> 00:08:53,150
at this point in time?
134
00:08:53,570 --> 00:08:58,070
How can we know if we found a duplicate or not?
135
00:08:58,940 --> 00:09:01,490
Well, that can be kind of tricky.
136
00:09:01,820 --> 00:09:03,800
OK, but what I recommend?
137
00:09:04,100 --> 00:09:05,630
Because why can it be tricky?
138
00:09:05,630 --> 00:09:13,220
Because if the last element does not equal to two value sitting design, let's say equals to nine?
139
00:09:14,000 --> 00:09:15,710
And you do not know if you.
140
00:09:16,040 --> 00:09:17,240
Yeah, basically.
141
00:09:17,240 --> 00:09:19,880
Yeah, basically, we can't even do it without additional variable.
142
00:09:20,030 --> 00:09:22,730
We can ask a simple question if J.
143
00:09:23,390 --> 00:09:26,810
If J equals to 10, right?
144
00:09:27,680 --> 00:09:34,520
If Jake was 10, because it means that we have iterated over all of the elements right here and we did
145
00:09:34,520 --> 00:09:35,480
not find four.
146
00:09:35,600 --> 00:09:36,650
Amy J.
147
00:09:36,860 --> 00:09:41,000
We did not find that this condition was satisfied.
148
00:09:41,390 --> 00:09:46,730
Then we reached the J equals to 10, and the condition right here was not satisfied and we moved on.
149
00:09:47,180 --> 00:09:49,220
That means that we did not.
150
00:09:51,130 --> 00:09:53,140
Find any.
151
00:09:55,050 --> 00:10:04,440
Duplicate value or value, is that index, say then in this case, what we can do is basically, say
152
00:10:04,440 --> 00:10:05,170
the following.
153
00:10:05,250 --> 00:10:10,590
If that's the case, let's print f the value set index say OK.
154
00:10:11,690 --> 00:10:15,720
Unique value and here print percentage.
155
00:10:16,250 --> 00:10:20,540
And here, print something like that, OK, so let's go.
156
00:10:22,400 --> 00:10:22,980
Print.
157
00:10:23,000 --> 00:10:25,970
I don't know what values at index, I write.
158
00:10:26,950 --> 00:10:28,810
Thing that's correct, yeah.
159
00:10:29,350 --> 00:10:34,000
And also, we can do count what where was it unit count?
160
00:10:34,840 --> 00:10:35,290
What was it?
161
00:10:35,510 --> 00:10:37,000
Yeah, unit count plus plus.
162
00:10:38,730 --> 00:10:40,530
So is it clear what do we do here?
163
00:10:41,370 --> 00:10:47,880
So we ask if Jake will stay 10, then it means that we not find any duplicate value, then print unique
164
00:10:47,880 --> 00:10:50,070
value and also unique count.
165
00:10:50,670 --> 00:10:56,610
And now they're approached to do this, OK is create additional variable and call it, I don't know,
166
00:10:56,630 --> 00:11:00,270
into found duplicate.
167
00:11:01,820 --> 00:11:04,550
Duplicate equals to zero.
168
00:11:06,290 --> 00:11:13,510
OK, and this will say that we need not found a duplicate and we will say if we did find a duplicate,
169
00:11:13,520 --> 00:11:15,740
that's another approach we can say.
170
00:11:16,100 --> 00:11:19,550
We can say found duplicate equals to one right?
171
00:11:19,550 --> 00:11:22,190
And then here we can ask if.
172
00:11:23,230 --> 00:11:30,520
Found duplicate does not equal to one, meaning we did not find duplicate for this value, right?
173
00:11:31,030 --> 00:11:38,830
Then printf and unique count plus plus and finally, before the beginning of the next iteration set
174
00:11:38,830 --> 00:11:43,210
found duplicate equal to zero and then increment the itself.
175
00:11:44,720 --> 00:11:52,460
OK, so let's try to run it and see what happens and if it works correctly and exactly as we expected
176
00:11:52,460 --> 00:11:53,570
it to work.
177
00:11:54,110 --> 00:11:55,310
Let's go like this.
178
00:11:55,610 --> 00:11:58,160
OK, so let's use the values that we have here.
179
00:11:58,160 --> 00:12:06,470
So five seven three four five, six, eight, nine, 10 and three so unique values.
180
00:12:06,470 --> 00:12:07,010
Seven.
181
00:12:07,310 --> 00:12:07,910
Here it is.
182
00:12:08,150 --> 00:12:11,660
Four, six, eight, nine and 10.
183
00:12:12,170 --> 00:12:12,830
Awesome.
184
00:12:13,310 --> 00:12:17,210
So all the unique values seemed to be found in this example.
185
00:12:17,750 --> 00:12:18,320
Great.
186
00:12:19,580 --> 00:12:23,630
Now finally, what we need to do is also to print total unique numbers.
187
00:12:24,200 --> 00:12:25,500
So they asked what was missing.
188
00:12:25,520 --> 00:12:26,780
So we are going to print.
189
00:12:27,080 --> 00:12:27,710
Total.
190
00:12:28,550 --> 00:12:29,450
Total.
191
00:12:30,510 --> 00:12:35,970
Unique numbers, and we are going to print it out to the screen.
192
00:12:36,360 --> 00:12:39,060
And that should be the unique count.
193
00:12:39,660 --> 00:12:40,440
That's it.
194
00:12:41,280 --> 00:12:41,820
All right.
195
00:12:42,270 --> 00:12:48,870
So once again, what's happening here is that we start, Okay, I'm going to show you one or two iterations
196
00:12:48,870 --> 00:12:49,890
to make it clear to you.
197
00:12:50,520 --> 00:12:55,770
So we start with this outer loop with start with equals to zero.
198
00:12:56,010 --> 00:12:59,430
And in the inner loop, we start that e j equals to zero.
199
00:12:59,820 --> 00:13:05,550
So we start with here, I and J both here we ask if I equals to J.
200
00:13:05,580 --> 00:13:06,090
Yes.
201
00:13:06,330 --> 00:13:08,070
So continued through the next iteration.
202
00:13:08,370 --> 00:13:09,320
Seth J.
203
00:13:09,330 --> 00:13:10,410
To be equal to one.
204
00:13:10,950 --> 00:13:12,480
So now J equals two one.
205
00:13:13,230 --> 00:13:20,080
We ask if values at Index I, which is one which is index zero, equals two values at Index J.
206
00:13:20,730 --> 00:13:24,120
If yes, then simply set found duplicate equal to one.
207
00:13:24,360 --> 00:13:27,600
And also, you can just break from here, OK?
208
00:13:27,840 --> 00:13:30,260
To save it from additional.
209
00:13:30,270 --> 00:13:35,340
What is it to save it from additional, unnecessary checking?
210
00:13:35,610 --> 00:13:35,960
OK.
211
00:13:35,990 --> 00:13:39,630
So if you found a duplicate, there is.
212
00:13:40,440 --> 00:13:43,230
There is no reason to continue.
213
00:13:44,140 --> 00:13:45,280
This for a loop.
214
00:13:45,700 --> 00:13:53,410
OK, so if you found it awesome, if not, let's basically move on again to these for a loop.
215
00:13:53,920 --> 00:13:56,260
Now Jay will be equal to two.
216
00:13:57,450 --> 00:13:57,840
Right.
217
00:13:59,160 --> 00:14:03,960
If it is equal, then awesome, if not, let's move to the G equals to three.
218
00:14:05,110 --> 00:14:09,100
Now, Jay, here and then Jay here, right, Jay equals two four.
219
00:14:09,430 --> 00:14:15,900
And now we found out that values hitting Dixie whenever I equals two zero equals devalues value index
220
00:14:15,940 --> 00:14:17,680
J one J equals two for.
221
00:14:18,620 --> 00:14:25,130
In this case, what we do is we set these flag found duplicate equal to one and we break break from
222
00:14:25,130 --> 00:14:29,600
where break from this inner loop and we go right here.
223
00:14:30,380 --> 00:14:35,800
So we ask, we found duplicate does not equal to one, then what we that's what we do otherwise.
224
00:14:36,090 --> 00:14:37,210
OK, let's go.
225
00:14:37,220 --> 00:14:40,070
Found duplicate equals to zero and then we start again.
226
00:14:41,000 --> 00:14:45,680
So in this case, we can also improve it a little bit because there is actually no reason to set it
227
00:14:45,680 --> 00:14:46,010
here.
228
00:14:46,010 --> 00:14:52,790
We can also do this operation right here because otherwise it will always be zero as well, but it would
229
00:14:52,790 --> 00:14:53,940
work the same way.
230
00:14:54,530 --> 00:15:00,680
And yeah, then you stop and you move on and increment I by one, meaning you move on.
231
00:15:01,790 --> 00:15:07,160
To the next value that you are going to check, J comes back to be equal to zero.
232
00:15:07,160 --> 00:15:09,290
So that's I, and that's Jay.
233
00:15:09,650 --> 00:15:13,930
And then you go again, you compare seven and five and then you ask, that's the same sum.
234
00:15:13,940 --> 00:15:14,720
Do not compare it.
235
00:15:14,720 --> 00:15:17,900
Then you compare seven and three and so on and so forth.
236
00:15:19,230 --> 00:15:19,650
OK.
237
00:15:20,220 --> 00:15:21,460
So I hope that's clear.
238
00:15:21,480 --> 00:15:25,920
Guys, let's make the final is execution for this exercise and use here.
239
00:15:26,190 --> 00:15:26,730
What was it?
240
00:15:27,060 --> 00:15:35,940
Five seven three four five six eight, nine, 10 and three and total unique numbers is zero, but nothing
241
00:15:35,940 --> 00:15:36,660
was printed.
242
00:15:37,020 --> 00:15:38,220
What was wrong?
243
00:15:39,580 --> 00:15:42,610
What was wrong, what what did we do wrong here?
244
00:15:42,930 --> 00:15:46,900
One second found duplicate break.
245
00:15:48,200 --> 00:15:49,100
Oh, I'm.
246
00:15:50,500 --> 00:15:54,340
But I think, you know, what was it one second?
247
00:15:56,180 --> 00:15:57,830
Oh, yes, sorry about that.
248
00:15:58,160 --> 00:16:03,440
So, yeah, that was the problem, we should not be here, obviously, because we only reach this place
249
00:16:03,440 --> 00:16:07,700
when found on duplicate equal to zero, so it definitely should be here.
250
00:16:08,030 --> 00:16:11,210
And maybe you should also be under the L section.
251
00:16:11,210 --> 00:16:14,060
So that's also a good option for it to be.
252
00:16:14,390 --> 00:16:16,190
OK, but now it should work.
253
00:16:16,220 --> 00:16:22,310
OK, so that was yeah, I guess we problem that was fixed immediately.
254
00:16:22,340 --> 00:16:23,990
So let's make sure now it works.
255
00:16:23,990 --> 00:16:31,430
Hopefully, bugs are always something that we should expect, but hope not.
256
00:16:31,550 --> 00:16:34,640
See, but yeah, that's basically what happens.
257
00:16:34,650 --> 00:16:39,920
So, yeah, so here it is, unique values and there it is totally unique names.
258
00:16:40,580 --> 00:16:42,290
So I hope everything is clear, guys.
259
00:16:42,650 --> 00:16:46,610
Let me know if you have any questions, feel free to ask whatever it is.
260
00:16:47,480 --> 00:16:52,030
And also, please feel free to leave some feedback and review.
261
00:16:52,040 --> 00:16:54,200
It helps me a lot in creating these content.
262
00:16:54,530 --> 00:16:56,330
It helps me also to improve it.
263
00:16:56,330 --> 00:17:01,010
And it's really nice to see your feedback once in a while.
264
00:17:01,550 --> 00:17:03,060
So thank you guys for watching.
265
00:17:03,080 --> 00:17:08,300
My name is Vlad of Lisa's Alpha Tech and I wish you a great day by.
23113
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.