LiveRamp Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




Comment hidden because of low score. Click to expand.
1
of 3 vote

You already got the answer, just xor them all, the result is the one showing odd times.

- Anonymous January 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

XOR all numbers.
Result is the required number

- Nitin Gupta January 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
2
of 2 votes

@anish and @gocool:-

Question clearly says that exactly one integer occurs odd number of times.

@anish and @gocool: All three integers in your test case occurred odd number of times.

- Nitin Gupta January 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
-2
of 2 votes

@nitin:
I am not sure how you interpret it. But this is what it is.
The question is that there is an array of size N and values range from 0 to N-1. Every integer occurs once except one that occurs odd number of times(instead of some of the integers - so atleast two of the numbers in the sequence from 0 to N-1 is missing). We find that number that occur odd number of times( > 1).

- gocool January 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Coudnt it be solved using hashmap, key as the number and values of the frequency of its occurences.

- Anonymous February 03, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Not in O(1) space...

- Johnb February 13, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 3 vote

As the question says, only one interger occurs odd number of times.
If you XOR any number with itself, it will result in 0. Thus, you can think of it as all integers which occur even number of times will cancel out each other.

Hence the final number which would remain at last will be the number which had odd-frequency.

- Ritesh January 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int find_duplicate_element( int * elements, int n) {

int dup;
for(int i = 0 ; i < n ; i++){
if(elements[elements[i] - 1] < 0) {
//elements[i] -1 to account for array starting from 0
dup = elements[i];
break;
}
else{
elements[elements[i] - 1] = - elements[elements[i] - 1];
}
}

for(int i = 0 ; i < n ; i ++) {
elements[i] = elements[i] < 0 ? -elements[i] : elements[i] ;
}
return dup;
}

- Anonymous January 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

sorry corrected version of above code, didnt note integers are in the range 0 to n-1

int find_duplicate_element( int * elements, int n) {

int dup;
for(int i = 0 ; i < n ; i++){
if(elements[elements[i]] < 0) {

dup = elements[i];
break;
}
else{
elements[elements[i]] = - elements[elements[i]];
}
}

for(int i = 0 ; i < n ; i ++) {
elements[i] = elements[i] < 0 ? -elements[i] : elements[i] ;
}
return dup;
}

- Anonymous January 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How about the solution based on RadixSort?

public int findSingle(int A[]) {
if(A == null || A.length == 0)
return -1;
for(int i=0; i<A.length; i++) {
while(i != A[i]) {
if(A[i] == A[A[i]])
return A[i];
else{
int tmp = A[A[i]];
A[A[i]] = A[i];
A[i] = tmp;
}
}
}
return -1;
}

- YukiWang December 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

As already mentioned,XOR each invidividual bits: Java solution my attempt: Optimization can be done not to through all the 32 bits of integer.. Time Complexity :O(32N) Space: O(1)

private static int findOddOccurenceNum(int [] integers) {
		//get the ith bit
		int missingNum = 0;
		for (int i = 0; i < 32; i++) {
			int missingBit = 0;
			for (int j = 0; j < integers.length; j++) {
				missingBit = missingBit ^ (integers[j] & (1<<i) );
			}
			if(missingBit!=0) {
				missingNum |= (1<<i);
			}
		}
		return missingNum;
	}
	
	public static void main(String[] args) {
		int [] integers = new int  [] {-2,2,2,3,3};
		System.out.println(findOddOccurenceNum(integers));
	}

- naren December 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

isn't this O(n^2)

- bhavi March 13, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

hi,

Is the input always sorted?

- sreevathsan.ravi February 02, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

If the quetion is as @gocool has restated

"The question is that there is an array of size N and values range from 0 to N-1. Every integer occurs once except one that occurs odd number of times(instead of some of the integers - so atleast two of the numbers in the sequence from 0 to N-1 is missing). We find that number that occur odd number of times( &gt; 1)."


Then
Number = sum of array - sum of from 0 to N-1

- mr x January 08, 2013 | Flag Reply


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More