Interview Question


Country: United States




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

Question lacks clarity.Should have more inputs to find k.

- Dhass April 13, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Nothing unclear. Find one integer not present in the array.

What more do you need?

For instance, you could try returning max+1, or min-1, but since you are given 32 bit signed integers, you have to be careful about overflows.

- Anonymous April 13, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

O(n) solution with O(n) memory:

Input array: A of length n

1. Find min value of the input, lets call it X. O(n)

2. if X!=Integer.MIN then output=Integer.MIN (corner case)

3. Create a boolean array of length n with default value FALSE. Lets call it P.

4. The idea is to check if the input array contains numbers from X to X+(n-1) using n sized boolean array. Then output is any element that is missing from the range X to X+(n-1) and if none are missing then the output is X+n, unless X+n=Integer.MAX in which case the input array contains all possible integers from Integer.MIN to Integer.MAX.

for(i = 0 to n-1) {
	j=A[i]-X
	if(j<n) then P[j]=TRUE
}

for(i=0 to n-1) {
	if P[i]==FALSE then output is Integer.MIN+i
}

if i==n && n!=(Integer.MAX+1-Integer.MIN) then output is Integer.MIN+n
else "no output"// corner case of input array containing all integers

--- O(n)

e.g
Input A = {1,-1,Integer.MIN,2,3,5}
X = Integer.MIN
P = {TRUE,FALSE,FALSE,FALSE,FALSE,FALSE}
Output = Integer.MIN+1

- Karthik April 14, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think may be the questions is, "Find the missing number in a continuous integers"

-> Find the sum of integers.
-> Sum the array.
-> Take the difference gives the exact number

- Prashanth April 16, 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