1 00:00:01,710 --> 00:00:02,400 Hi, everyone. 2 00:00:02,430 --> 00:00:05,070 So today we're going to solve this question to some. 3 00:00:06,250 --> 00:00:10,120 OK, so what is the problem, Mr. So but honestly, it is very simple. 4 00:00:10,150 --> 00:00:16,760 You will be given in broderie indigent pottery and you will be given a target value. 5 00:00:16,930 --> 00:00:17,830 So what do you have to do? 6 00:00:17,860 --> 00:00:21,030 You have to find two numbers in the area. 7 00:00:22,260 --> 00:00:27,930 And if he will add those two numbers, the sum of those two numbers will basically be close to the target 8 00:00:27,930 --> 00:00:28,260 value. 9 00:00:28,740 --> 00:00:32,229 OK, so in this case, the target will lose nine. 10 00:00:32,460 --> 00:00:35,950 So we have to find to number inside this area. 11 00:00:36,180 --> 00:00:40,650 Houssam, if we will add those two numbers, then we will reach the target value. 12 00:00:41,190 --> 00:00:47,760 OK, so in this case, you can see if you will add two and you will add seven, then seven plus two. 13 00:00:47,820 --> 00:00:49,790 OK, so two plus seven. 14 00:00:49,830 --> 00:00:50,920 That is basically nine. 15 00:00:51,810 --> 00:00:56,040 OK, so what we have to do then we have to return the indexes of these two numbers. 16 00:00:56,500 --> 00:00:57,830 OK, so this is zero. 17 00:00:57,840 --> 00:01:02,080 One, two, three, four, five, six and seven. 18 00:01:02,280 --> 00:01:09,810 So basically my answer basically be it will contain index four and index seven. 19 00:01:09,870 --> 00:01:12,090 OK, so my answer will be for seven. 20 00:01:13,300 --> 00:01:16,310 OK, so I hope you understand the discussion I'm repeating myself. 21 00:01:16,360 --> 00:01:22,030 You have to find number inside the area such that if you will add those two numbers, you will reach 22 00:01:22,030 --> 00:01:23,020 the target value. 23 00:01:23,080 --> 00:01:26,170 OK, so target value will be provided by the user. 24 00:01:26,230 --> 00:01:27,880 OK, so this will be inpart. 25 00:01:28,850 --> 00:01:34,550 The target will lose nine, if you will add two and seven, then you will reach the target value and 26 00:01:34,550 --> 00:01:37,190 what we have to do then we have to return the indexers. 27 00:01:38,110 --> 00:01:45,370 Of the elements of the area now have against all discussion, so the first way, this is the brute force. 28 00:01:46,490 --> 00:01:47,920 Arrogance and naive approach. 29 00:01:48,460 --> 00:01:52,090 So what we will do, we will just erode over the area. 30 00:01:52,450 --> 00:01:54,220 OK, so pick one element. 31 00:01:54,490 --> 00:01:57,280 So what I'm trying to say here is pick one element. 32 00:01:57,640 --> 00:01:58,760 I am picking 11. 33 00:01:59,080 --> 00:02:01,140 OK, what is the target value? 34 00:02:01,150 --> 00:02:02,740 So target value is basically nine. 35 00:02:03,070 --> 00:02:06,820 Now, what we have to find, we have to search for minus two inside the three. 36 00:02:08,350 --> 00:02:12,520 OK, so this new approach says pick one element. 37 00:02:14,360 --> 00:02:21,050 And find the other one, pick one element, let's say this element is the nail that is a let's say this 38 00:02:21,050 --> 00:02:22,240 element is Alfy. 39 00:02:23,350 --> 00:02:28,120 And then it is after picking that one element search for that element in the area. 40 00:02:28,730 --> 00:02:32,350 OK, so the search for that element inside the heading. 41 00:02:33,370 --> 00:02:37,810 And what is the other element so that element does nothing but target. 42 00:02:38,810 --> 00:02:39,980 Minus Afie. 43 00:02:41,920 --> 00:02:48,250 So in this case, if I will pick 11, then target is basically nine minus 11, so basically we have 44 00:02:48,250 --> 00:02:50,710 to find minus two inside the area. 45 00:02:51,130 --> 00:02:55,360 So what I will do, I will I dread what Daddy and I will try to find. 46 00:02:55,360 --> 00:02:57,550 Minus two, obviously, minus two is not present. 47 00:02:58,740 --> 00:03:00,930 Then what I will do, I will pick 15. 48 00:03:02,470 --> 00:03:09,160 After picking 15, but we have to do I will search the Eddie, so nine minus 15 is basically minus six. 49 00:03:09,520 --> 00:03:13,270 So I will search this area for minus six. 50 00:03:13,270 --> 00:03:15,010 Obviously, minus six is not present. 51 00:03:15,370 --> 00:03:18,270 Then I will pick this element one. 52 00:03:18,760 --> 00:03:25,990 OK, then I will search the area for the element to it because one plus eight is nine, but it is not 53 00:03:25,990 --> 00:03:26,440 present. 54 00:03:26,680 --> 00:03:33,340 Then I will pick element four and then I will search the area for the element five because four plus 55 00:03:33,340 --> 00:03:35,710 five is nine, but five is not present. 56 00:03:36,020 --> 00:03:37,960 OK, then I will pick two. 57 00:03:39,120 --> 00:03:45,990 I will pick two and then I will search daddy, I will search this area for the element seven because 58 00:03:45,990 --> 00:03:52,020 two plus seven is nine and seven is present, OK, and we will get our answer. 59 00:03:52,200 --> 00:03:55,590 So I will return the index of two and I will return the index of seven. 60 00:03:55,920 --> 00:03:58,290 So that's how I will be able to solve this question. 61 00:03:58,520 --> 00:04:00,660 OK, so the approach is very simple. 62 00:04:01,080 --> 00:04:05,520 You just have to pick one element and then you have to search for that element. 63 00:04:05,940 --> 00:04:10,820 OK, so what it will look like so you will have for loop, you will have two loops. 64 00:04:10,830 --> 00:04:13,380 OK, so one loop is for picking the element. 65 00:04:13,570 --> 00:04:18,450 So this will start from zero and lattices iList and end and I placeless. 66 00:04:18,779 --> 00:04:19,829 And what do you have to do. 67 00:04:20,190 --> 00:04:23,390 So pick one element and after picking. 68 00:04:23,400 --> 00:04:27,210 So this outer loop is basically picking one element. 69 00:04:28,380 --> 00:04:34,930 This is for picking element and then you will have in a loop and what the A loop is. 70 00:04:34,950 --> 00:04:40,410 So basically what is what we have to find for let's say it's a name Miski Suki's nothing but target 71 00:04:40,410 --> 00:04:46,110 value, which will be given by the user minus the current element element that we have picked. 72 00:04:46,800 --> 00:04:48,380 And then you will have one loop. 73 00:04:48,960 --> 00:04:51,030 So this loop, let's say the name of the variable is J. 74 00:04:51,060 --> 00:04:52,700 So this will start from my plus one. 75 00:04:52,710 --> 00:05:02,400 It will go till the end of the array and it will check if the array element, which is if that element 76 00:05:02,400 --> 00:05:05,070 is close to the key or not. 77 00:05:05,580 --> 00:05:08,390 OK, so what is the time and the space complexities. 78 00:05:08,390 --> 00:05:09,290 So time, complexity. 79 00:05:09,300 --> 00:05:10,650 Basically there are two loops. 80 00:05:10,980 --> 00:05:14,950 So the time, complexities and squared and what is the space complexity. 81 00:05:14,970 --> 00:05:17,070 So we are not using any extra space. 82 00:05:17,250 --> 00:05:19,530 So the space complexity is basically big off when. 83 00:05:21,060 --> 00:05:23,870 OK, so this is the brute force approach. 84 00:05:25,190 --> 00:05:27,380 OK, so obviously we can do much better. 85 00:05:28,500 --> 00:05:29,770 How they can do much better. 86 00:05:29,790 --> 00:05:32,430 So what we are doing here is we are picking one element. 87 00:05:34,040 --> 00:05:40,580 We are picking one element, so it will take outdraw and time, and then we are searching the area for 88 00:05:40,580 --> 00:05:41,500 the second element. 89 00:05:41,510 --> 00:05:43,730 So it will also take big oftentime. 90 00:05:45,110 --> 00:05:46,730 So can we optimize this time? 91 00:05:46,730 --> 00:05:47,840 Too big of one. 92 00:05:48,440 --> 00:05:51,320 Can we searching over time in question time? 93 00:05:51,530 --> 00:05:53,210 Yes, we can do the searching. 94 00:05:53,480 --> 00:05:56,630 We can do the searching question with the help of Hashmat. 95 00:05:58,420 --> 00:06:04,990 OK, in strip searching is big often, OK, we can assume in Hashmat searching this basically big Goffman, 96 00:06:05,330 --> 00:06:11,920 so we are picking every element that will take lot of time, but for searching, but for searching inside 97 00:06:11,920 --> 00:06:14,390 the area, we will take constant time. 98 00:06:15,100 --> 00:06:20,020 So basically our time complexity will become all that often and the space complexity since we are using 99 00:06:20,020 --> 00:06:21,850 a hash map so it will become more Draffin. 100 00:06:22,090 --> 00:06:26,170 OK, so we are improving on the time, but we are taking extra space. 101 00:06:26,920 --> 00:06:28,320 But that's not a problem again. 102 00:06:29,200 --> 00:06:30,830 Space is generally not a problem. 103 00:06:31,840 --> 00:06:33,460 Now how we can use hash map. 104 00:06:34,570 --> 00:06:40,440 So let us consider a small example and let's see how we can take the help of Hashmat. 105 00:06:41,200 --> 00:06:46,960 OK, so let's say for seven to nine, eight, five and three. 106 00:06:47,040 --> 00:06:49,090 OK, and what is their target value? 107 00:06:50,950 --> 00:06:54,700 So let's say the target value is, well, OK, let's say the target we lose. 108 00:06:54,740 --> 00:06:57,290 Well, OK, so let's make it thirteen. 109 00:06:57,610 --> 00:06:58,320 This is 13. 110 00:06:58,360 --> 00:07:02,710 OK, so yes, I have nine plus three, which is total. 111 00:07:03,520 --> 00:07:07,120 OK, so let's see what we can how we can use the hash map. 112 00:07:07,660 --> 00:07:09,400 So I will create a hash map. 113 00:07:11,280 --> 00:07:17,430 What is the key and what will be the value so key will be basically element will be element and the 114 00:07:17,430 --> 00:07:24,240 value will basically be the index, because you can see because you can see in the question what we 115 00:07:24,240 --> 00:07:25,010 have to write down. 116 00:07:25,020 --> 00:07:27,270 So we have to return basically the indexes. 117 00:07:27,510 --> 00:07:29,700 OK, we have to return the indexes. 118 00:07:29,700 --> 00:07:31,350 So we have to store index. 119 00:07:32,600 --> 00:07:37,470 So in this case, two plus seven is basically nine, so I have to return the index. 120 00:07:37,490 --> 00:07:39,560 So this is index zero, this is an index one. 121 00:07:39,710 --> 00:07:43,880 So I am returning zero one since I have to return the index in the equation. 122 00:07:44,150 --> 00:07:46,790 So that's why the value will be index. 123 00:07:46,910 --> 00:07:47,360 OK. 124 00:07:48,440 --> 00:07:54,560 Now, how we can use hash map, so let us out right over there and we will prepare our hash map and 125 00:07:54,560 --> 00:07:56,340 simultaneously we will get our answer. 126 00:07:56,480 --> 00:07:57,260 Let's see how. 127 00:07:57,950 --> 00:08:00,470 So I'm standing here and my hash map is empty. 128 00:08:01,280 --> 00:08:02,520 So I'm standing at four. 129 00:08:02,840 --> 00:08:04,710 So what I will do, what is the value? 130 00:08:04,730 --> 00:08:08,480 So I have to search for so basically 12 minus four is basically it. 131 00:08:08,930 --> 00:08:09,360 OK. 132 00:08:09,560 --> 00:08:11,770 Now search it inside the hash map. 133 00:08:12,230 --> 00:08:13,610 So search it inside. 134 00:08:13,610 --> 00:08:18,020 The hash map is empty so you will not be able to find it. 135 00:08:18,770 --> 00:08:20,120 OK then move ahead. 136 00:08:20,400 --> 00:08:26,300 So while moving ahead, push the element inside the hash map so the element will be four and its index 137 00:08:26,300 --> 00:08:26,690 is zero. 138 00:08:27,680 --> 00:08:29,450 Now I'm standing at seven. 139 00:08:31,030 --> 00:08:35,559 Now, what we have to do, so we have to find that element five, OK, so five is already present, 140 00:08:35,570 --> 00:08:37,750 let's change its value to six. 141 00:08:37,780 --> 00:08:39,760 OK, so this is basically six. 142 00:08:41,039 --> 00:08:48,480 So I am standing at five now, I have to find element five now searching the map, so element five is 143 00:08:48,480 --> 00:08:54,770 not there, then move ahead and when you are moving ahead, push the element inside the hash map. 144 00:08:54,990 --> 00:08:57,540 So the element is seven and it's indexes one. 145 00:08:59,130 --> 00:09:07,170 Now you are standing at two so far to my target values, 12 to find then obviously ten is not present 146 00:09:07,170 --> 00:09:08,700 inside the map. 147 00:09:08,730 --> 00:09:12,840 OK, so I am doing searching inside the hash map and is not present. 148 00:09:13,140 --> 00:09:16,140 Then move ahead and push to inside the map. 149 00:09:16,590 --> 00:09:18,750 So element is two and it's a nexus to. 150 00:09:20,000 --> 00:09:27,350 Now, nine, OK, so far, nine would have to do I have to find three, I have to find three inside 151 00:09:27,350 --> 00:09:28,010 the hash map. 152 00:09:29,090 --> 00:09:33,440 So trees not present, then move ahead and push, eliminate. 153 00:09:33,590 --> 00:09:36,320 So I am pushing eliminate and it's indexes three. 154 00:09:37,430 --> 00:09:44,900 So this is element 13, so for element 13, obviously what we have to do, so I will search for minus 155 00:09:44,900 --> 00:09:49,120 one, I will search for minus one inside the Hashmat minus one is not present. 156 00:09:49,130 --> 00:09:53,090 So I will push Tartine and it's a Nexus four and then I will move ahead. 157 00:09:53,450 --> 00:09:54,440 So I will come here. 158 00:09:55,310 --> 00:10:00,580 So this is element six, so four element six, that that element should be six. 159 00:10:00,960 --> 00:10:02,350 OK, six six Qestrel. 160 00:10:02,630 --> 00:10:06,890 So search for six inside the hash map and obviously six is not present. 161 00:10:06,890 --> 00:10:09,160 Then move ahead and push six. 162 00:10:09,530 --> 00:10:12,080 So I have six and it's indexers Nexus five. 163 00:10:13,100 --> 00:10:15,890 OK, then what I will do so I will reach here. 164 00:10:17,730 --> 00:10:23,940 Three, four, three, what I will do, I have to find nine inside the Hashmat find a nine inside the 165 00:10:24,010 --> 00:10:24,470 Hashmat. 166 00:10:24,660 --> 00:10:26,930 So nine is present inside the ship. 167 00:10:27,270 --> 00:10:28,830 And what is the index of nine. 168 00:10:28,830 --> 00:10:30,600 Index of nine is basically three. 169 00:10:31,530 --> 00:10:33,470 And what is the index of this element? 170 00:10:33,960 --> 00:10:36,140 So the index of this element is basically six. 171 00:10:36,720 --> 00:10:38,530 So our answer will be three commas. 172 00:10:39,000 --> 00:10:45,540 OK, so forgetting the element of forgetting the index of Element nine, I am storing the index. 173 00:10:45,550 --> 00:10:47,690 That's why this value has to be index. 174 00:10:48,680 --> 00:10:55,740 OK, so after finding out nine I will get its index, which is three and the index of the current element, 175 00:10:55,740 --> 00:10:56,360 which is six. 176 00:10:56,370 --> 00:11:00,000 So I will prepare my answer three comma six and then I will return my answer. 177 00:11:00,390 --> 00:11:06,090 OK, so one thing to note here is if you want to search inside the hash map, you can only search element. 178 00:11:06,360 --> 00:11:07,830 You cannot search index. 179 00:11:08,100 --> 00:11:11,940 OK, we can only basically hash map this nothing. 180 00:11:12,400 --> 00:11:13,520 Does that give a little bit. 181 00:11:14,330 --> 00:11:15,870 OK, it is a dual appearance. 182 00:11:15,870 --> 00:11:20,360 So if you want to find something inside the hash map, you can only do searching with the help of key. 183 00:11:20,760 --> 00:11:22,350 You can only search key. 184 00:11:23,630 --> 00:11:25,180 You cannot search value. 185 00:11:25,230 --> 00:11:29,030 OK, we cannot search value, we can only search. 186 00:11:30,140 --> 00:11:35,270 OK, so our key will be element and our value will basically be index. 187 00:11:36,120 --> 00:11:38,780 OK, so now let us write the gold. 188 00:11:39,920 --> 00:11:40,340 OK. 189 00:11:44,550 --> 00:11:47,730 So what they have to return, so we have to return that part of integers. 190 00:11:48,480 --> 00:11:50,640 OK, so let's see. 191 00:11:53,670 --> 00:11:55,410 I have a bit of indigestion, sir. 192 00:11:55,980 --> 00:11:56,400 OK. 193 00:11:57,830 --> 00:12:01,880 So now let us take our hash map, so I'm using, I don't know, the map. 194 00:12:03,170 --> 00:12:04,280 So Redmap. 195 00:12:05,710 --> 00:12:11,590 What will the key silkies basically integer and the value will basically be in beta also. 196 00:12:11,740 --> 00:12:13,540 OK, name is Map. 197 00:12:14,790 --> 00:12:17,910 Now, let us just trade our daddy so forint. 198 00:12:19,360 --> 00:12:20,440 Let's change the name. 199 00:12:21,830 --> 00:12:22,720 A OK. 200 00:12:24,350 --> 00:12:25,460 So says. 201 00:12:30,930 --> 00:12:33,870 Now, what we have to do, we have to search for. 202 00:12:36,160 --> 00:12:43,350 So search what we have to search, we have to search Dogood minus Elfy inside the hash map. 203 00:12:43,810 --> 00:12:46,170 OK, now let us search inside the map. 204 00:12:47,080 --> 00:12:47,590 So. 205 00:12:49,510 --> 00:12:54,650 My map that you can use can't function or you can find the function. 206 00:12:54,990 --> 00:12:59,020 OK, so let us use common function. 207 00:12:59,050 --> 00:12:59,470 So. 208 00:13:00,890 --> 00:13:07,070 OK, so let us use fine function, so fine function will take and put Askey again, what is the key 209 00:13:07,070 --> 00:13:08,020 keys such. 210 00:13:09,470 --> 00:13:10,280 So if. 211 00:13:11,470 --> 00:13:14,920 The key is not present, so that will be my daughter and. 212 00:13:20,490 --> 00:13:25,680 So basically, if the key is not present inside the map, then what we have to do, we have to push 213 00:13:25,680 --> 00:13:27,620 the current element inside the map. 214 00:13:27,630 --> 00:13:28,500 So my map. 215 00:13:29,470 --> 00:13:38,300 What is the key is the current element, Elfy, and what is the index indexes, a OK in the part we 216 00:13:38,320 --> 00:13:42,090 have found of a search element inside the map, then what do we have to do? 217 00:13:42,100 --> 00:13:43,570 We have to prepare our answer. 218 00:13:43,630 --> 00:13:45,940 OK, so answer that. 219 00:13:45,940 --> 00:13:46,450 Push back. 220 00:13:46,450 --> 00:13:47,830 We have to push two elements. 221 00:13:48,010 --> 00:13:49,450 We have to push two indexes. 222 00:13:50,120 --> 00:13:51,970 OK, what the first index. 223 00:13:51,980 --> 00:13:54,740 So first index will basically be you can see here. 224 00:13:55,780 --> 00:13:58,410 So the first index is basically the index of nine. 225 00:13:58,650 --> 00:14:01,690 OK, and how we can obtain index three. 226 00:14:01,690 --> 00:14:04,840 It is nothing but my map of nine. 227 00:14:05,230 --> 00:14:07,060 Minimum of nine is basically three. 228 00:14:07,340 --> 00:14:07,750 OK. 229 00:14:10,220 --> 00:14:20,240 So this is nothing but my map of nine and what is nine nine basically is is the search element search. 230 00:14:23,020 --> 00:14:25,120 And let us push the current index. 231 00:14:29,890 --> 00:14:31,030 So what is the current index? 232 00:14:31,060 --> 00:14:31,690 It is a. 233 00:14:33,460 --> 00:14:33,970 And. 234 00:14:35,040 --> 00:14:36,090 We can it out on. 235 00:14:37,140 --> 00:14:41,610 OK, so this is the computer, let us in our court and then we will try to submit our gold. 236 00:14:45,920 --> 00:14:48,200 OK, so what is the problem here? 237 00:14:50,230 --> 00:14:53,890 OK, so what we have to do for the completion purposes. 238 00:14:55,830 --> 00:14:58,710 See the return type of dysfunction, what does that entail? 239 00:14:58,740 --> 00:15:00,100 This is a bit of deja vu. 240 00:15:00,150 --> 00:15:05,040 OK, so for the compilation purpose, I have to return answer here also. 241 00:15:12,710 --> 00:15:15,290 OK, so I did a mistake here, basically. 242 00:15:16,810 --> 00:15:21,250 Court should be in the effort and basically let's make it. 243 00:15:22,280 --> 00:15:29,630 And OK, so if we are not able to find the search element, then I will push and if we are able to find, 244 00:15:29,630 --> 00:15:30,980 then I will prepare my answer. 245 00:15:31,010 --> 00:15:31,340 OK. 246 00:15:33,440 --> 00:15:36,660 OK, so our goal is working fine on let's try to some real. 247 00:15:42,510 --> 00:15:44,820 OK, so our goal is working fine, OK? 248 00:15:44,850 --> 00:15:46,380 Our goal is hundred percent correct. 249 00:15:47,130 --> 00:15:49,230 Now let's see how our goal is working. 250 00:15:56,250 --> 00:16:00,360 Let us try another gold for this and put two, seven, 11 and 15. 251 00:16:00,420 --> 00:16:07,470 OK, so first thing that we get out of it, nettelhorst you do because I have to return a vector of 252 00:16:07,470 --> 00:16:08,010 integer. 253 00:16:08,040 --> 00:16:13,500 OK, so basically if we will not rate the return statement here, you will get the compilation error 254 00:16:13,740 --> 00:16:19,820 and the compiler will be basically due redo because we have to return integer and we were not returning 255 00:16:19,830 --> 00:16:22,200 anything, although this line will never get executed. 256 00:16:22,350 --> 00:16:29,910 OK, we will always be able to find our answer if there exist one lucky Artus that this input. 257 00:16:31,230 --> 00:16:34,570 So this is my map, which is empty. 258 00:16:35,430 --> 00:16:38,520 OK, so my map is initially empty now. 259 00:16:39,610 --> 00:16:41,020 Well, we are retreating the. 260 00:16:41,260 --> 00:16:45,480 So first element is basically to OK, so target minus two. 261 00:16:45,760 --> 00:16:49,440 So Target is basically nine, so nine minus two, which is basically seven. 262 00:16:49,660 --> 00:16:52,450 And then what we are doing, I'm using defined function. 263 00:16:52,480 --> 00:16:57,200 So fine function is the inbuilt function and fine function will take input ascii. 264 00:16:57,940 --> 00:17:02,970 OK, I told you we can only search, we can not search value, we cannot search value. 265 00:17:02,980 --> 00:17:04,589 I can only search with the help of key. 266 00:17:05,040 --> 00:17:08,069 OK, so I'm searching ke. 267 00:17:09,180 --> 00:17:10,980 And gives basically seven. 268 00:17:11,339 --> 00:17:18,690 OK, so, so lucky seven inside the map, and obviously you will not be able to find seven because the 269 00:17:18,690 --> 00:17:19,560 map is empty. 270 00:17:19,710 --> 00:17:20,520 So what will happen? 271 00:17:20,520 --> 00:17:21,869 You will reach the end point. 272 00:17:22,079 --> 00:17:24,089 OK, now, look, suppose this is a map. 273 00:17:26,190 --> 00:17:32,090 And I suppose there are some countries, OK, let's say two, three and five, you are finding seven. 274 00:17:32,370 --> 00:17:34,490 So seven is not pleasant inside the map. 275 00:17:34,500 --> 00:17:36,240 So this is the end point. 276 00:17:36,410 --> 00:17:38,800 OK, this is not and this is not. 277 00:17:38,800 --> 00:17:40,760 And this is the end of the map. 278 00:17:42,090 --> 00:17:43,530 So I don't know what will happen. 279 00:17:43,830 --> 00:17:48,480 You will search seven and finally you will reach the end of the map. 280 00:17:48,960 --> 00:17:52,440 So if you will reach the end of the map equals equals my map. 281 00:17:52,440 --> 00:17:56,310 Norton, if you will reach the end, that means seven is not present. 282 00:17:56,730 --> 00:18:01,860 So if the seven is not present, what I am doing, I'm inserting element and its index. 283 00:18:01,870 --> 00:18:04,890 OK, so my map will look like this. 284 00:18:06,120 --> 00:18:12,450 I am inserting the element, Afie, which is to and I'm inserting its index, which is zero. 285 00:18:12,630 --> 00:18:14,190 OK, so comma zero. 286 00:18:16,740 --> 00:18:20,100 Now move ahead, so I will come to the Element seven. 287 00:18:21,190 --> 00:18:25,730 I will come to the element seven now for Element seven, which does not target value. 288 00:18:26,230 --> 00:18:27,320 What is my social value? 289 00:18:27,550 --> 00:18:29,690 So I have to search for two. 290 00:18:29,740 --> 00:18:36,790 OK, so nine minus seven is to target, minus seven is to search to inside the map my map, not find 291 00:18:36,790 --> 00:18:37,130 two. 292 00:18:37,690 --> 00:18:40,180 So if you will find if you will search for two. 293 00:18:41,510 --> 00:18:42,900 Yes, to his present. 294 00:18:43,190 --> 00:18:45,140 So basically, this condition is false. 295 00:18:45,380 --> 00:18:46,930 OK, you will not reach the end. 296 00:18:46,940 --> 00:18:53,870 This is the end, so you will not reach and if you will not reach and you will prepare your answer, 297 00:18:53,870 --> 00:18:54,950 answer, not push back. 298 00:18:55,950 --> 00:19:01,810 So I am pushing the element so I don't push back my map of search, so my map off, too. 299 00:19:01,830 --> 00:19:09,000 So if you will right my map of two, then you will get the answer to zero, which is the index. 300 00:19:09,060 --> 00:19:14,250 OK, so I am writing my map of search, which is basically zero, and I will push the element zero. 301 00:19:14,730 --> 00:19:17,160 Then I am pushing the current index, which is one. 302 00:19:17,610 --> 00:19:21,820 So I am pushing one so zero one and then I am returning my answer. 303 00:19:22,710 --> 00:19:24,420 So that's how this code is working. 304 00:19:24,720 --> 00:19:25,150 OK. 305 00:19:25,770 --> 00:19:28,500 OK, so this is basically the key Mitchellville integer. 306 00:19:28,680 --> 00:19:30,680 This is the value which will also be integer. 307 00:19:31,200 --> 00:19:33,510 Then I have to search for the element search. 308 00:19:34,880 --> 00:19:40,190 If the element you are trying to find is not present inside the map, then you will reach the end of 309 00:19:40,190 --> 00:19:47,360 the map, OK, if the element you want to search is not present inside the map, then you will reach 310 00:19:47,600 --> 00:19:48,850 the end of the map. 311 00:19:49,070 --> 00:19:51,660 If you are reaching the end of the map, that does not present. 312 00:19:51,680 --> 00:19:53,570 That means push the current element. 313 00:19:53,720 --> 00:19:56,060 OK, so I am pushing the current element. 314 00:19:57,050 --> 00:20:04,370 And if you are not reaching map dot, and that means the element is present, OK, if you are not reaching 315 00:20:04,370 --> 00:20:08,370 the end, that means the target, the search value is present. 316 00:20:08,390 --> 00:20:14,840 OK, so the search value is present in the search values present, simply prepared to answer and return. 317 00:20:15,170 --> 00:20:21,560 OK, so my search, it will have done me the index and this is the current index and then I'm returning 318 00:20:21,560 --> 00:20:22,250 my answer. 319 00:20:22,450 --> 00:20:25,750 OK, so as discussed the time complexity. 320 00:20:26,840 --> 00:20:29,130 So what is the time and the space complexity. 321 00:20:29,510 --> 00:20:30,930 So what is the time complexity. 322 00:20:30,950 --> 00:20:38,270 So assuming there are assuming they look up in the hash map is big off once all the time, complexities 323 00:20:38,270 --> 00:20:42,230 big often and the space complexities big often for the hash map. 324 00:20:42,260 --> 00:20:42,650 OK. 325 00:20:45,830 --> 00:20:52,130 So searching in my place over time, OK, we can resume searching, takes over and bamburgh of one time. 326 00:20:52,160 --> 00:20:55,730 OK, so this is the time in the space complex waiting for this solution. 327 00:20:55,970 --> 00:20:58,350 OK, so if you have any doubt in this question, you can ask me. 328 00:20:58,370 --> 00:20:58,790 Thank you.