• 2 months ago
Single Element in Sorted Array | Binary Search | D..
Transcript
00:00Hi everyone, welcome to the complete DSA series in which we are going to do an important question
00:08which is to find the single element in a sorted array.
00:10Apart from this, if we want to read any other concept in DSA, we will get it in this playlist
00:14on this channel.
00:15So let's talk about the question, single element in a sorted array.
00:19This question is also problem no.
00:20540 on LeetCode.
00:21In this, we have an array named as numbers.
00:25In this array, every single element appears twice, i.e. exactly twice.
00:30There is only a single element which appears exactly once.
00:33We have to identify that single element and we have to return it from the function.
00:37For example, we have this array.
00:40All the elements in this array are arranged in sorted order.
00:43And all the elements in this array appear twice.
00:461 appears twice, 3 appears twice, 4 appears twice, 8 appears twice.
00:51There is only a single element 2 which appears exactly once, so our answer is going to be
00:56equal to 2.
00:57Similarly, we have one more array.
00:58Now, the last element in this array, this should not be here.
01:02So, these are the elements that appear in our array.
01:05In this, every element appears exactly twice.
01:08We only have an element 10 which appears once, so our answer is going to be equal to 10.
01:12So, our job is to identify this single element from our sorted array.
01:17Now, there are multiple approaches to solving this question.
01:21Our brute force approach will be linear search.
01:24Linear search basically says that if all the elements are arranged in sorted order, then
01:28we can check on each element whether we get that single element.
01:32What will be the single element?
01:34Single element is basically that element which neither matches with its previous element
01:38nor matches with its next element.
01:39Because if all the elements are arranged in sorted order, then the value of all the elements
01:44is equal, they will either exist one ahead or one behind.
01:47So, who will be our single element?
01:49Let's suppose if we are on any index i, then the value that neither matches with its array
01:55of i minus 1 nor matches with its array of i plus 1, this becomes our single value.
02:01So, we can search for that single element by going to each index and the time complexity
02:05that we will get in this search will be big O of n.
02:07Along with this, there can be another approach using bitwise operators, but even in that
02:10approach, we will get the same time complexity.
02:12Now, this is a brute force approach, big O of n, time complexity code.
02:15Almost all of us students will be able to write it, so we are not going to discuss it.
02:18We will discuss our optimized time complexity code.
02:21In the question, it is given that the solution must run in log n time complexity and big O
02:27of 1 space.
02:28In space, we do not have to use any extra array, any extra prefix, suffix type of array.
02:32We have to keep big O of 1 space and we have to try to solve this question in log n time
02:36complexity.
02:37Now, as soon as we hear for any question that we have a sorted array and we have to solve
02:43our question in log n time complexity, that is, what do we have to use?
02:46We have to use binary search.
02:48Apart from that, in fact, if we had given a sorted array and our job was to find a single
02:52element, then whenever it comes to searching in a sorted array, we should always think
02:56about binary search at least once.
02:58So, to solve this question, we are going to use binary search algorithm.
03:03And how will we use this algorithm?
03:05First of all, let's discuss normal binary search.
03:08Normally, in binary search, we start with our start.
03:12For example, in this array, we will start with our end.
03:16And using this, the first step is to find the mid value.
03:19Mid for us is start plus end minus start divided by 2.
03:23Generally, start plus end by 2 is there, but it has an optimization to prevent overflow,
03:27for which we use this formula.
03:29And the second step is that we check that the value, the target that we have to find
03:33in normal binary search, does it exist on our mid value?
03:36So, how do we find out here?
03:38Here we have to find out our single element.
03:41So, we can check whether our mid is our single element or not.
03:45And the condition to identify it is that if we take the array of mid instead of i,
03:50then how will we know that the array of mid is a single element?
03:53When this value does not match the value of mid minus 1 and does not match the value
03:57of mid plus 1.
03:58So, this is a single element.
04:00This is pretty straightforward.
04:01If our array of mid is not equal to array of mid minus 1 and not equal to array of mid plus 1,
04:12it means that we have got our answer and we will return our mid value from here.
04:17So, the process of such a binary search is pretty straightforward.
04:20We did not face any difficulty in this.
04:22But if we do not get our answer on mid, then what should we do in that case?
04:26For example, let's take the example of this array.
04:28We have our start, we have our end.
04:30So, if we talk about this, this index will be our mid.
04:33So, this part will be our left and this part will be the right of mid.
04:37So, now when we compare mid, whether it is a single element or not,
04:40we will know that mid matches with its previous element.
04:43It means that this is not our answer.
04:44So, the next and most important step of binary search is to identify the search space.
04:50What do we do in the step of search space identification?
04:52We choose whether our answer should be in the left or in the right.
04:56This step is the most important because this is the reason why time complexity log-in occurs.
05:00This is the reason why our search space, i.e. where our answer can exist,
05:03is halved in every iteration at every step.
05:07So, how can we decide standing on mid
05:10that our single element should exist in the left or in the right.
05:15This is the most important part in solving the problem.
05:18And to solve this, we will use a lot of logic.
05:21So, let's clear things a little.
05:24These are our two important steps which we have already figured out.
05:27Now, we are trying to figure out our third step,
05:30which is to pick the search space.
05:31How do we figure out whether we will get our single element in the left or in the right?
05:36Let's think about it.
05:37If we know in our question that all the elements appear twice,
05:41i.e. if we have any n number of elements,
05:44i.e. here one element is 1, 2, 3, 4, 8,
05:48all the unique elements are equal to n.
05:51If every element appears twice,
05:53can we say what will be the total size of our array?
05:56The total size of our array will always be even.
05:59If we have elements 1, 3, and 5,
06:02and we said that 1, 3, and 5 appear twice every time,
06:04then we will have 1, 1, 3, 3, 5, 5,
06:07this will be our even size array.
06:10But in the question, we always have an odd size array given.
06:16Why is it given? Because these elements appear twice.
06:18Plus, one element will always appear once.
06:21Because of this, the array given in the question will always be an odd size array.
06:25Because of this extra single element.
06:28For example, look at example 1.
06:30We have an odd number of elements in it.
06:32Look at example 2.
06:33We have an odd number of elements in it.
06:35Because it makes sense.
06:36And whenever we find an odd size array,
06:39we know that our left side will also have an equal number of elements.
06:42Our right side will also have an equal number of elements.
06:44For example, here we calculated our mid for our array.
06:48We know that we have an equal number of elements on the left side of this mid.
06:52We also have an equal number of elements on the right side, which is equal to 4.
06:55Now we logically know that if perfect duplicates exist anywhere,
06:59perfect duplicates means that every element will have a duplicate.
07:02And exactly one duplicate will be there.
07:04So the size of that array always comes out to be even.
07:07And wherever there is an extra single value with duplicates,
07:13its size always comes out to be odd.
07:15This is a logical thing that we have logically recognized.
07:18Now once we have identified our mid for our array.
07:22For example, here we have identified this mid.
07:24So we know that there is an even number of elements in its left half.
07:27What is in the right half?
07:28There is an even number of elements.
07:30So what can I say?
07:31If this 3 matches with this 3,
07:33means it matches with the number before itself,
07:36then how many remaining elements will remain?
07:38The remaining elements will become odd.
07:39And wherever there is an odd element,
07:41our single value exists there.
07:44I will repeat this again because it is a very important step.
07:47If I take out my mid,
07:48and I find out that there is an even number of elements in the left part.
07:52There is an even number of elements in the right part too.
07:54So my answer should either be mid or exist in the left and right.
07:57Because these are total odd number of elements.
07:59So I have to find out whether I will get the answer in the left or right.
08:02So for that, I can simply compare this mid value with its previous and next element.
08:07If the mid value in our array is equal to the array of mid-1,
08:12in which case there is an even number of elements in the left part.
08:16So can we say that this 3 will pair up with this 3?
08:19If 3 pairs up with 3,
08:21then if we observe this part of the array carefully,
08:23then the total number of elements here becomes odd.
08:25If this 3 pairs up with 3,
08:27then definitely the remaining elements will also remain odd.
08:30So our single element should exist in the left part only.
08:35Only then we will get a single element plus all the other duplicates.
08:39And the duplicates of the remaining even numbers in the right part already exist.
08:43So let's write this thing logically once.
08:45If we find out that there is an even number of elements in the left and right part,
08:51and after that we find out that our mid is matching with its previous.
08:57The next condition is that our array of mid is equal to array of mid-1.
09:03So in that case, we know that our answer will always exist in the left side.
09:07Why will it exist?
09:08Because there is an even number of elements in the left side.
09:10Now these two pairs up,
09:11so the remaining odd number of elements remain in the left side.
09:14So wherever there are odd elements,
09:15there is always a single element with our duplicate.
09:18And that is the logic that we are trying to follow.
09:20What will be its opposite case?
09:22We can take an example of its opposite case.
09:24Let's suppose we are given this array.
09:26Now when we find mid in this array,
09:28then we will get this mid value.
09:30Now there are even number of elements in the left and even number of elements in the right part of this mid value.
09:35Now this mid value is not the answer because it is matching with its next.
09:38But because there were even number of elements in its right side,
09:42but one of them is its match,
09:45so how many remaining elements are left?
09:46Remaining elements are odd elements.
09:48And wherever there are odd elements,
09:50there is a combination of duplicates and singles.
09:52That means our answer will exist in the right side in this case.
09:56So its opposite case will be that when our mid matches with its next element i.e. mid plus one,
10:01then our answer will be in the right side in that case.
10:03Now if there is any mid that does not match with both left and right,
10:06then that is the answer.
10:07So either it will always match with the left or it will always match with the right.
10:10So in any case, there will be even number of elements in our left and right parts.
10:13When it matches with the left with the previous,
10:15then we will get our answer in the left.
10:17When it matches with the right,
10:18then in that case we will get our answer in the right.
10:20So this is the logic that we will be applying to write our binary search approach.
10:25Now it is not necessary that every time when we take out our mid,
10:27then even number of elements exist in both our left and right parts.
10:31It is also possible that odd number of elements exist in our left and right parts.
10:35For example, take the example of this area.
10:37In this area, 1, 2, 3, 4, 5, 6, 7 elements exist.
10:41In fact, if we want, we can draw the boundary here.
10:43When we take out the mid in this area,
10:45then it is going to be this value.
10:47Now we know that we have an odd number of elements in the left of the mid.
10:50We also have an odd number of elements in the right of the mid.
10:53So what should we do in this case?
10:54Let's figure it out once.
10:55This is our second case.
10:57Very similar to this,
10:59in which we have odd number of elements in the left and right.
11:03In this case, if we see the odd number of elements,
11:05then we know that our mid matches with the previous element.
11:08Now if our mid matches with the previous element,
11:11then these two have made a pair.
11:13And what are the remaining numbers?
11:15Remaining numbers are even numbers.
11:17So it means that the condition of perfect duplicate exists here.
11:20No single element can exist.
11:22Let me repeat this.
11:24In the beginning, these elements were 3, 3, 7.
11:27These were the elements of the left side.
11:29And 7 was my mid element.
11:30Now 7 has made a pair with 7.
11:32So what are the remaining elements?
11:33Remaining elements are always even number of elements.
11:35Because these were odd.
11:36But if we subtract 1 from odd,
11:38then even number of elements are left.
11:39It means that what are they forming?
11:40They are forming a perfect duplicate.
11:41No single element will exist here.
11:43It means that where will our single element exist?
11:46Our single element will exist in the second half,
11:48that is, in the right side.
11:50Which is absolutely true.
11:51Because 10 exists in the right side.
11:53So the logic we get from here is the opposite logic.
11:56That if the value of the array of mid minus 1
12:00is equal to the array of mid,
12:01then the answer will exist in the right side.
12:03When there are odd number of elements in the left and right part.
12:06And what will happen in the opposite case?
12:08In the opposite case, when the value of our mid will be equal to the array of mid plus 1,
12:12then our answer will exist in the left side.
12:14Let's see an example of this.
12:16Let's suppose we have this array given.
12:18When we take out mid in this array,
12:19then this will be our mid value.
12:20With whom is the mid value matching?
12:21It is matching with the right.
12:22What are the remaining numbers?
12:23The remaining numbers are even numbers.
12:25It means that we can completely ignore the right side.
12:27The answer will not exist in the right.
12:29The answer will exist in the left.
12:30Because the single element is now on the left side.
12:32Odd numbers are left.
12:33It has paired up with it.
12:34So where there are odd numbers,
12:35our single element exists there.
12:37So now where do we have to search?
12:38Now we have to search on the left side.
12:39And our single element 7 in this array
12:41exists on the left side.
12:43So this is an overall approach we have taken
12:46to identify whether we will search for the answer
12:48on the left side or on the right side
12:50on every level.
12:52We have decided that we cannot get our single element
12:54on both sides.
12:55The single element will be found on one side only.
12:56So this is the logic with which we define
12:58whether the single element will be found on the left side
12:59or on the right side.
13:00Now let's see how we will identify
13:02whether there is an even number of elements
13:03or an odd number of elements
13:04in our left and right parts.
13:06This is going to be a very simple step.
13:08I mean, I don't think we will have to use a lot of brain
13:10in this.
13:11Because I have shown you the cases here.
13:13In this case, our mid becomes 3.
13:15There is an even number of elements in the left and right.
13:17In this case, our mid becomes 7.
13:19There is an odd number of elements in the left and right.
13:21If our mid value
13:23Here our mid value is 4k equal.
13:25Here our mid value is 3k equal.
13:27If our mid value is even
13:29If the mid index is even
13:31In that case, there is always an even number of values
13:33in the left and right parts.
13:35If our mid is an odd index
13:37then there will always be an odd number of values
13:38in the left and right half.
13:39This is very logical.
13:40Because in the question, we have already found
13:42that the total array
13:45will always be an odd array.
13:47Because a single element always exists in it.
13:49In that case, we can conclude that
13:51if our mid modulo 2 is equal to 0
13:53means our case is even
13:55and if mid modulo 2 is not equal to 0
13:58which we can simply write our else case
14:00what will happen?
14:02This will be our else case.
14:04In this case, we will get an odd number of values.
14:06And in fact, the conditions we have written here
14:08we don't need to check both the conditions.
14:10If mid
14:12doesn't match with the previous element
14:14then it will always match with the next element.
14:16Because if it doesn't match with both
14:18then that will be our answer.
14:20In this case, we don't need to check with the second condition.
14:22In that case, we can simply write else.
14:24In this case also, we don't need to check with the second condition.
14:26That will simply be the else of this condition.
14:28This will be the else of this condition.
14:30This is our overall logic on the basis of which
14:32we will be applying our binary search.
14:34Now let's dry run this logic on our examples.
14:36Let's suppose we started with this array.
14:38In this array, we will get our start
14:40we will get our end
14:42and we will get our mid value.
14:44This is our mid.
14:46Now we will compare the mid.
14:48Is our mid not the answer?
14:50The answer will be that which will not match with left or right.
14:52But here, mid is matching with the left side.
14:54So, mid is not the answer.
14:56After that, the third step will be
14:58to identify whether we have an even number of elements
15:00in the left right half or an odd number of elements.
15:02We will see here that the value of mid is equal to 4.
15:04That means we have an even number of elements.
15:06When we have an even number of elements
15:08then we will see whether it is matching with the left or right side.
15:10Our mid is matching with the left side.
15:123 and 3 are matching.
15:14That means our answer will lie in the left side.
15:16In binary search, this means that
15:18we will update the end and bring it to
15:20mid minus 1.
15:22This time, we will repeat our process.
15:24After the third step, we will go to the first step again
15:26and calculate our mid again.
15:28If we calculate the mid again,
15:30this time our mid will be this value.
15:32For 1, we will check whether 1 is a single element or not.
15:34Then we will check
15:36how many elements exist in the left side of the mid.
15:38Odd number of elements exist in the left side of the mid.
15:40Now we will check
15:42with whom is the mid value matching.
15:44If the mid value is matching with the first value,
15:46then our answer is in the right side.
15:48Being in the right side means that
15:50if our current search space was this much,
15:52then in the next step,
15:54our answer will be
15:56within this much value.
15:58Again, we will update
16:00our start and end.
16:02For the next step, the end will remain the same.
16:04Start will be this value.
16:06If we calculate the mid, it will be equal to 2.
16:08Mid is pointing here.
16:10For 2, we will check whether it is a single element or not.
16:122 does not match with left or right.
16:142 is the mid element.
16:16From here, we will return
16:18not the value of mid but the value of area of mid.
16:20Because we have to return that single element
16:22from our answer.
16:24Let's write the pseudocode of this approach.
16:26We are going to start value of 0
16:28and an end value of n minus 1.
16:30Just like binary search,
16:32we will run a while loop
16:34when start is less than or equal to end.
16:36We have to get our mid every time.
16:38Mid is going to be equal to
16:40start plus n minus start divided by 2.
16:42After that, we will check whether mid is our answer.
16:44If mid is not the answer, how will we know?
16:46If the value of area of mid
16:48is not equal to
16:50area of m minus 1
16:52and this is also not equal to
16:54area of m plus 1.
16:56In that case, mid is our answer.
16:58In that case, we can return
17:00the value of area of mid
17:02as our final answer.
17:04Otherwise, next step will be to check
17:06whether we have odd number of elements or even number of elements.
17:08For this check, we will write
17:10if mid modulo 2 is equal to 0
17:12then it means this is the condition of even number of elements
17:14and the case of else
17:16is the condition of odd number of elements.
17:18When we have even number of elements,
17:20in the case of even, we have to check
17:22if it matches with previous, then we have to go left
17:24or we have to go right.
17:26If it matches with previous,
17:28then the value of area of m minus 1
17:30is equal to area of m.
17:32In that case, we have to go left.
17:34Going left means mid is equal to minus 1.
17:36This condition is already seen in binary search.
17:38In plain binary search,
17:40we know that going left means
17:42we have to update our end pointer
17:44and bring it back.
17:46Else condition is that we have to go right.
17:48Going right means
17:50mid is equal to plus 1.
17:52Similarly, we will check the condition of odd.
17:54In the case of odd, if it matches with previous,
17:56then the answer is either right or left.
17:58Here we can write that
18:00if area of m minus 1
18:02is equal to area of mid,
18:04then in that case,
18:06we have to go right.
18:08Going right means start is equal to mid plus 1.
18:10In the case of else,
18:12we have to go left.
18:14Going left means end is equal to mid minus 1.
18:16This is our overall logic
18:18of binary search approach.
18:20Why are we calling it binary search?
18:22Because we are doing it on every level.
18:24Whenever we are going right,
18:26whenever we are going left,
18:28we are deciding which other half we want to discard.
18:30If we say that this is our area
18:32and our answer will exist on right side,
18:34then it means we are completely
18:36discarding left side.
18:38That is how we are applying binary search.
18:40Because of this logic,
18:42our time complexity will be big of log n.
18:44Because we did not use any extra space,
18:46our space complexity will be big of 1.
18:48This is the time complexity.
18:50There is one additional optimization
18:52When we are applying these checks,
18:54we are comparing mid with mid minus 1
18:56and mid with mid plus 1.
18:58If we take an example of any array,
19:00there can be any mid value in that array.
19:02If we have started from here
19:04and we have ended here,
19:06then with time,
19:08our mid value can be any value
19:10in the entire search space.
19:12This means that
19:14there can be a case
19:16when our single element exists here
19:18and our mid value becomes 0
19:20If our single element exists here,
19:22then our mid value becomes n minus 1.
19:24When mid value is 0,
19:26then mid minus 1 will not exist.
19:28When mid value is n minus 1,
19:30then array of mid plus 1
19:32will not exist.
19:34We can handle these two conditions
19:36either outside the while loop
19:38or inside the while loop.
19:40Basically, we have to write special if conditions
19:42to handle these two conditions.
19:44If we want,
19:46we can handle them inside the while loop.
19:48What we have to do is
19:50to simply check for these two conditions.
19:52This will be our overall logic.
19:54For these two conditions,
19:56we will check for mid is equal to 0.
19:58We will check
20:00if our mid value becomes 0
20:02and if this is the answer.
20:04When will 0 be the answer?
20:06It will be the answer when
20:08our first element does not match with 0.
20:10For example, here 1 is written
20:12and here 2 and 3 are there.
20:14What is this 1 doing?
20:161 is our single element.
20:18When the value of array of 0
20:20is not equal to
20:22array of 1,
20:24then we have to return
20:26array of mid as our answer.
20:28In this case, write array of mid or array of 0.
20:30Both are same because mid is 0.
20:32How will we handle the second case?
20:34In the second case,
20:36if the value of mid is equal to n minus 1
20:38and
20:40if this is our single element.
20:42In the case of single element,
20:44let's suppose value is equal to 7
20:46and here 6, 6, 5, 5, 4, 4
20:48are the values.
20:50What will 7 do? It will never match with
20:52its previous element.
20:54Here we will know that array of n minus 1
20:56is not going to be equal to array of n minus 2.
20:58In this case,
21:00we will return array of mid
21:02as our answer.
21:04Whether we write array of mid or array of n minus 1,
21:06both have same logic.
21:08We can understand these two as edge cases
21:10or corner cases which we have handled
21:12in this video.
21:14One more additional thing.
21:16When we are comparing array of 0 with array of 1
21:18or n minus 1 with n minus 2,
21:20we are assuming that
21:22the size of our array is bigger than 1.
21:24That is why n minus 2 exists for n minus 1.
21:26When we are doing these checks,
21:28we are assuming that
21:30at least more than one element should exist in our array.
21:32But we can also have an array
21:34in which only single element exists.
21:36Let's suppose we get this array.
21:38This is the array
21:40in which 5 exists.
21:42The answer will be equal to 5
21:44because 5 is a single element.
21:46We will have to handle this case
21:48outside our while loop.
21:50If the value of n is 1,
21:52then we know that
21:54our answer will be equal to array of 0.
21:56This is a single element case
21:58which we can handle outside
22:00because we are assuming that
22:02more than one element exists in our array.
22:04This is the overall logic
22:06which we are going to convert into code
22:08This is the function
22:10which we have to complete.
22:12I am going to rename
22:14this nums as a.
22:16First of all,
22:18let's take out n
22:20which is the size of our array.
22:22a.size is done.
22:24Let's handle our smallest base case.
22:26If the value of n is 1,
22:28then we know that
22:30our answer will be equal to our single element.
22:32If this is not the case,
22:34then we will take initialized with 0
22:36initialized with n-1
22:40Now, we will run a loop
22:42till the value of start is less than or equal to end.
22:44First of all, we will take out mid.
22:46mid is going to be equal to start plus n-start
22:48divided by 2
22:50Then we will check
22:52for these two corner cases.
22:54If the value of mid is 0
22:56and array of 0
22:58is not equal to array of 1
23:00In that case, we know that
23:02our answer will always be array of mid value
23:04Both the values are going to be same.
23:06First of all, this is our corner case
23:08which we have handled.
23:10Second corner case is of n-1
23:12In the case of n-1, we will compare n-1 and n-2.
23:14If both are not same,
23:16then the answer is array of mid.
23:18And third case
23:20which is this case
23:22where we can get the answer
23:24In that case, we will check
23:26if array of mid-1 is not equal to
23:28array of mid
23:30This is not a corner case.
23:32If this is not equal to array of mid
23:34and array of mid is also not equal to
23:36array of mid plus 1
23:38This means that this is our single element
23:40which exists.
23:42In this case also, our answer will be
23:44array of mid equal.
23:46We have calculated mid answer.
23:48Now, we will check for next conditions
23:50i.e. for odd and even conditions.
23:52If our mid modulo 2 is even
23:54In that case, we have to
23:56compare next mid with previous value.
23:58If array of mid minus 1
24:00is equal to
24:02array of mid
24:04then answer should exist in right.
24:06In case of even, answer should exist in left
24:08Existing left means
24:10the value of end will be equal
24:12If else, answer should exist in right
24:14Existing right means
24:16start will be equal to mid plus 1
24:18In case of odd,
24:20same conditions we have to check
24:22but this time conditions reverse.
24:24If we match with previous
24:26then we have to go to right
24:28we have to go to the right or we have to go to the left, which means end is equal to mid
24:33plus 1.
24:34I hope we are getting this.
24:35This is our even condition.
24:36In even, this is our left case, this is our right case, here in odd, this is our right
24:41case and this is our left case.
24:43So this is the overall logic which we are going to follow to apply binary search in
24:48this question.
24:49And if we do not get the answer, then we will return minus 1, but this statement of minus
24:521 will never be executed because the answer will always exist.
24:55So first of all, we have handled the smallest case, which is of single element array.
24:59After that, we have applied plain simple binary search, in which the binary search, the logic
25:04to halve the search space, we have modified it here.
25:08So this is modified binary search.
25:09The time complexity in this is again log n.
25:12The space complexity that is constant, before running it, let's fix our typo once, which
25:17is end should be equal to mid minus 1.
25:19Let us now run the code and if we want, we can submit it.
25:24And this is a successful submission.
25:25So this is how we solve our problem of single element in a sorted array.
25:55Let us now run the code and if we want, we can submit it.
26:51So this is how we solve the problem of finding the single element in a sorted array.
27:12So I hope that we have understood the whole question very well.
27:15If we have successfully completed the lecture, we can comment that we have successfully completed
27:19or we are done with the lecture.
27:20Apart from this, you can also share your progress with me on Twitter regarding the DSA series,
27:23which we are doing.
27:24We are going to do a lot of questions and concepts in this.
27:27So you will get the link of Twitter in the description box below.
27:29That's all for today.
27:30See you in the next video.
27:31Till then keep learning and keep exploring.

Recommended