## Interview Question

• -1
of 1 vote

Country: United States

Comment hidden because of low score. Click to expand.
0
of 2 vote

``````#include<iostream>

using namespace std;

int main()
{
int arr[] = {3, 1, 4, 4, 5, 2};
int repeat = 0;
for(int i = 0; i <= 5 ; i++)
repeat = repeat^arr[i]^i;

cout<<repeat;

}
Output:- 4``````

Comment hidden because of low score. Click to expand.
0

your code doesn't work for this input {3, 1, 4, 10, 5, 10}.

Comment hidden because of low score. Click to expand.
0

``325``

Comment hidden because of low score. Click to expand.
0
of 0 vote

is there constraint on time complexity..?

1. Sort the array
2. Compare current element with next element, if they are same break the loop.

Comment hidden because of low score. Click to expand.
0
of 0 vote

is there constraint on time complexity..?

1. Sort the array
2. Compare current element with next element, if they are same break the loop.

Comment hidden because of low score. Click to expand.
0
of 0 vote

IF EXTRA SPACE is ALLOWED

use hashSet in java .

1. create a new hashSet HS
2. for every element in the array, check if hashSet contains the element (using HS.contains(element)) .
if the method returns False , then add the element in the hashSet .
3. Traverse next element in arrray and repeat step 2.

Space Complexity: O(n)
Time Complexity: O(n)

Comment hidden because of low score. Click to expand.
0
of 0 vote

IF EXTRA SPACE IS NOT ALLOWED .
IF array elements are from 1 to N

Duplicate element = (Sum of array of elements) - (Sum of numbers from 1 to n)

Space Complexity: O(1)
Time Complexity: O(n)

Comment hidden because of low score. Click to expand.
0
of 0 vote

We need to understand the question better. What is the significance of n=5? Does it mean that it will always have numbers from 1 to 5? if so, then sum of all digits from 1 to 5 = n(n+1)/2 = 15. And sum of the array is 19... 19-15 = 4.

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.