1. Shizuka’s lucky number will surely be present.
2. There will only be a single lucky number.
The first line contains a single integer ‘N’, representing the total number of elements present in Shizuka’s list.
The next line contains ‘N’ single-spaced elements, representing the elements of Shizuka’s list
Print an integer denoting the lucky number of Shizuka.
1 <= N <= 10^5
0 <= data <= 10^9
Where ‘data’ is the value of elements of Shizuka’s list.
Time Limit: 1 sec
You do not need to print anything, it has already been taken care of. Just implement the given function.
The idea here is to use the fact that the array is sorted and the element of the array (‘arr[i]’) is unique if it doesn't have an adjacent element that has the same value as ‘arr[i]’.
Algorithm:
The idea here is to store the frequency of elements of the array in a hashmap. Then we will traverse all elements of hashMap and the element whose frequency is 1 will be our answer.
Algorithm:
The idea here is to use the fact that the bitwise xor of two numbers is zero. So, we will do the xor of all elements of the array, and all the numbers which occur twice get canceled out. So, in the end, we will get the number that occurs only once.
For example
Array = [1, 1, 3, 3, 5, 7, 7]
Here 1 ^ 1 ^ 3 ^ 3 ^ 5 ^ 7 ^ 7 = 5
As 1 ^ 1 = 3 ^ 3 = 7 ^ 7 = 0
Algorithm:
The idea here is to use binary search and move left and right using the below observation.
Algorithm:
Search In A Sorted 2D Matrix
Ninja And The Strictly Increasing Array
Maximum GCD
Negative To The End
Fake Coin Problem