Find Unique Element in Array
You have been provided an integer array/list ARR
of size N
. Here, N
is equivalent to 2M + 1
where each test case has M
numbers appearing twice and one number appearing exactly once.
Your task is to identify and return this unique number that appears only once.
Example:
Input:
t = 2
N = 5
ARR = [1, 2, 3, 2, 1]
N = 7
ARR = [4, 5, 6, 7, 7, 6, 5]
Output:
3
4
Explanation:
In the first test case, 3
is the only number that is not repeated. In the second test case, 4
is the number which appears only once.
Constraints:
1 ≤ t ≤ 102
0 ≤ N ≤ 103
- Time Limit: 1 sec
Note:
The unique element is guaranteed to be present in the array/list according to the given condition.
AnswerBot
1y
The task is to find the unique number in an array where all other numbers occur twice.
The array size is given by N = 2M + 1, where M is the number of elements occurring twice.
Loop through the array an...read more
IRFAN BEG
6mo
that arr has been called the
IRFAN BEG
6mo
the ans is 2
Add answer anonymously...
Top Josh Technology Group Front end Developer interview questions & answers
Popular interview questions of Front end Developer
Top HR questions asked in Josh Technology Group Front end Developer
>
Josh Technology Group Front end Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app