Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Question- Find Odd Occurring

Element
Problem Description
You are given an array. In which single type of element is in
pairs and are in contiguous form. Go through the array and
find element which single.
Example: -
INPUT- 1 ,1, 2, 2, 3, 3, 4, 4, 3, 600, 600, 4, 4
OUTPUT- The value is 3.
The index is 8.

Memory allocation…………

What are we going to do??


We are going to use the binary search and see if the element
on which the mid is standing, is also present at the next place
or the previous place and if its not present at of the places than
mid is the answer. We will do it after seeing the mid is even
or odd to determine the search side of the search space.

What will be our solution approach??


1. Create an array.
2. Create a function and call it.
3. Initialise all the variables used for binary search.
4. First condition if only one element is in the array after
searching then it is the odd occurring element. And return
start.
5. Coming to second condition, here we will check if the mid
is even or not to determine the search side of the search
space.
6. If the condition is true then we will have one more
condition inside which search in the right side by adding 1
to the mid index. And we will check that the upcoming
element is equal to the current element of mid and we will
update the start if found.
Else the end will be equal to mid. Because to check if the
element is in the one index before.
7. Now we will use the next condition to check if the element
is one index before. After this the loop will again work
vice- versa.

This was the explanation of my code.


So, Till the Byeeee……….

You might also like