1 00:00:02,440 --> 00:00:03,130 Hi, everyone. 2 00:00:03,160 --> 00:00:07,900 So in this video, we are going to solve this question, count the occurences of an element. 3 00:00:08,990 --> 00:00:16,610 So, for example, if this is already so the elements are, let's say, five, five, six, five and 4 00:00:16,610 --> 00:00:18,780 six, so the value of X is five. 5 00:00:19,010 --> 00:00:20,660 So how many times five is appearing? 6 00:00:20,660 --> 00:00:22,420 Seven times second time and third time. 7 00:00:22,670 --> 00:00:24,650 So five is better than the average three times. 8 00:00:24,650 --> 00:00:25,910 So output should be three. 9 00:00:26,570 --> 00:00:33,020 Similarly, if the value of existing so if the value of X is basically six, then six is present one 10 00:00:33,020 --> 00:00:34,310 time and second time. 11 00:00:34,520 --> 00:00:35,840 So output should be two. 12 00:00:36,800 --> 00:00:42,040 Similarly, if the value of X system so ten is not present inside the three, so output should be zero. 13 00:00:42,830 --> 00:00:45,960 So we can solve this question easily with the help of follow up. 14 00:00:45,980 --> 00:00:46,820 So what we will do. 15 00:00:48,270 --> 00:00:55,470 You're simply outraged over the ad, and whenever you see the value, let's take a variable answer. 16 00:00:55,800 --> 00:01:00,110 Whenever you see the value X, you will answer placeless and you will move ahead. 17 00:01:00,390 --> 00:01:02,040 Similarly, you will see the value again. 18 00:01:02,040 --> 00:01:08,250 You will you will again do answer Lespinasse and you will stop when you will reach the end. 19 00:01:08,370 --> 00:01:10,920 So we just need to maintain a variable answer. 20 00:01:10,920 --> 00:01:15,570 And whenever we see the X value, I will do answer. 21 00:01:16,320 --> 00:01:17,520 So let us write the code. 22 00:01:19,920 --> 00:01:21,910 So I'm not returning anything. 23 00:01:22,200 --> 00:01:25,410 I will take a variable, so one thing. 24 00:01:26,480 --> 00:01:33,020 We need to solve this question with the help of equation, and that is obvious there a functional void 25 00:01:33,820 --> 00:01:38,830 void, a function I will take areas in, but I will take a number of elements I for a rating of Arrietty 26 00:01:39,320 --> 00:01:46,400 X the value, and we will take this outside variable, we will take this outside variable and we will 27 00:01:46,400 --> 00:01:47,870 take this variable by reference. 28 00:01:48,170 --> 00:01:50,290 Initially, the value of this answer will be zero. 29 00:01:51,470 --> 00:01:52,880 So then we will write the code. 30 00:01:54,520 --> 00:02:00,400 So whenever we find the value I will do on C++ and initially the value of funds will be zero because 31 00:02:00,400 --> 00:02:05,370 I will call the function from me and I will pass the answer zero. 32 00:02:05,530 --> 00:02:10,389 And since I am printing the answer inside me, so I will print my answer inside mean. 33 00:02:10,660 --> 00:02:14,890 And that's why I need to pass the answer variable by reference. 34 00:02:14,900 --> 00:02:15,400 So. 35 00:02:17,080 --> 00:02:18,580 The name of the function is count. 36 00:02:20,060 --> 00:02:25,670 Count occurences or let's name it, count only, we will take it as input. 37 00:02:26,920 --> 00:02:34,060 We will take how many elements are there and we will take X, we will take the next time for our trading 38 00:02:34,060 --> 00:02:39,930 order and we will take on some variable Bio-Reference because we are going to paint the answer inside 39 00:02:39,950 --> 00:02:40,270 mean. 40 00:02:43,690 --> 00:02:45,220 So how I will call this function. 41 00:02:46,750 --> 00:02:53,830 So initially, let's create another variable here and say zero, I will call the function count, I 42 00:02:53,830 --> 00:03:00,640 will pass any I will pass a number of elements, which is six data, which I want to search for. 43 00:03:00,940 --> 00:03:02,310 I want to search for five. 44 00:03:02,320 --> 00:03:08,470 How many times five is appearing, how many times five is appearing in my data, I will start iterating 45 00:03:08,470 --> 00:03:11,310 from zero and answer variable. 46 00:03:13,040 --> 00:03:19,610 So this function will update the value of a variable and now we can print the answer here. 47 00:03:23,680 --> 00:03:27,100 Simple and let's come out. 48 00:03:28,470 --> 00:03:30,270 So this is count function. 49 00:03:34,220 --> 00:03:36,500 So here we can just copy this code. 50 00:03:45,790 --> 00:03:52,510 So if I become too close to him, then I will stop and return, if I is equal to X, then I do not need 51 00:03:52,510 --> 00:03:53,320 to print anything. 52 00:03:54,190 --> 00:04:01,450 I will just do answer placeless, so I will do answer placeless and I need to call the government function. 53 00:04:02,950 --> 00:04:08,750 And I will give answer also, and that is how I think our function will work. 54 00:04:09,160 --> 00:04:10,900 So let's test for five. 55 00:04:11,140 --> 00:04:13,690 So five is present one, two and three times. 56 00:04:13,720 --> 00:04:15,370 So five is three times. 57 00:04:15,730 --> 00:04:16,779 So arbitrary, arbitrary. 58 00:04:17,810 --> 00:04:19,640 So I didn't say semicolon. 59 00:04:22,740 --> 00:04:31,540 So output should be three and tasty, right, output, so let's say I want to search for six, six percent 60 00:04:31,590 --> 00:04:32,250 two times. 61 00:04:33,610 --> 00:04:40,150 So this exists two times now let's test for seven, seven is present only one time. 62 00:04:41,750 --> 00:04:47,570 So seven is one and then is not pleasant inside, there is no output should be zero. 63 00:04:48,540 --> 00:04:49,770 So I put this zero. 64 00:04:50,710 --> 00:04:55,780 So our function is working, so this is it from this video, I will see you in the next one.