Qualcomm Interview Question for Software Engineer / Developers






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

- Pretty straight forward, given a sorted array find if an element exists using binary search. Complexity: O(logn)
- Find pivot = (left+right)/2, check if data == Arr[pivot], if yes return 1
- else if data<Arr[pivot], search in left half recursively
- if bigger search in right half recursively
- do till left>right

int binarySearch(int arr[],int x,int l,int r)
{
	int pivot = (l+r)/2;
        if(l>r)return 0;
	if(x == arr[pivot])return 1;
	else
	{
		if(x<arr[pivot]) return binarySearch(arr,x,l,pivot-1);
		else return binarySearch(arr,x,pivot+1,r);
	}
}

void main()
{
	int arr[5] = {12,18,22,54,63};
	int x = 22;
	if(binarySearch(arr,x,0,4))printf("Found %d",x);
	else printf("Did not Find %d",x);
}

Output: Found 22

- dnair89 March 12, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

<pre lang="java" line="1" title="CodeMonkey57905" class="run-this">public class binarySearch {

public int binarySrchRCR(int array[],int low,int high,int target){

int range = high - low;
int center = (range/2)+low;

if(range < 0){
System.out.println("Incorrect high and low");
} else if(range == 0 && array[low] != target){
System.out.println("Target not in array");
}

if(target == array[center]){
System.out.println("Target Found : "+array[center]);
return target;
}
else if(target < array[center])
return binarySrchRCR(array,low,center -1,target);
else
return binarySrchRCR(array,center+1,high,target);
}
}
</pre><pre title="CodeMonkey57905" input="yes">
</pre>

- Anonymous September 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Perfect ans!! :D

- Candida June 22, 2012 | 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