## EMC Interview Question for Software Engineer / Developers

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

Given: array is of integers.

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

This has been already discussed , we can do it with the help of Hash Map...with a complexity of o(1)

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

Hi,
can you please share link to the solution. I could not figure out o(1) solution. Are you sure about that? Isnt it o(log n)?

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

move in the step of power of ...
2,4,8, 16, 32,.. --> 2^i
moment u find a number less then or equal the required number stop.
if(num <= arr[2^i])
break
Apply binary search between the current index 2^i and 2^(i-1)

solution O(log n)

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

but i think he wants the first occurrence of the number.
so i think we need to apply binary search to find the number and then move left or right to find the first occurrence.

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

moron piece of shit solution

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

yeah ...the above solution is much better than hashing as hashing takes a preprocessing time of O(n) and space complexity of O(n) .

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

Why 2^i ? please explain.

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

We can directly apply binary search on this array because it is sorted.
Suppose an sorted array A[1..n].
In every step of binary search, we don't return if A[mid]==key.
Instead, we use this conditional statement:
if (key<=A[mid]) high=mid-1
else low=mid+1.
At last, we return value of low when low>high;
Time complexity is O(logN);

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