Qualcomm Interview Question for Software Engineer / Developers






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

int two_max (int *array, int size, int *first, int *second)
{
int i;
if (array == NULL && first == NULL && second == NULL && size < 2) return 0;

*first = a[0];
for (i = 1; i < size; i++)
{
if (*first <= a[i])
{
*second = first;
*first = a[i];
}
else if(*second <= a[i])
{
*second = a[i];
}
}
return 1;
}

- Karthik September 23, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void largest_two(int a[], int b[] )
{
int i;
for (i=0;i<9;i++) {
if (a[i] > b[0] ) {
b[0] = a[i];
}
if (a[i] > b[1] && a[i] < b[0])
b[1] = a[i];
}

}
void main() {
int a[10];
int b[2];
int i;

for (i=0;i<9;i++)
a[i] = random();

largest_two(a,b);
for (i=0;i<9;i++)
printf("a[%d]=%d \n",i, a[i]);
printf("\n");
for (i=0;i<2;i++)
printf("b[%d]=%d \n",i, b[i]);

}

- ed February 05, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool largest_two( int a[], int arraySize, int *largest, int *secondlargest)
{
    if( !arraySize ) return false;   /* Empty array */
    
    *largest = *secondlargest = a[0];
    
    for( i = 0; i < arraySize; i++ )
    {
       if( *largest < a[i] )
       {
           *secondlargest = *largest;
           *largest = a[i];
       }
    }
    return true;
}

- Anonymous April 04, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Wrong

- Anonymous January 17, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int two_max (int *array, int size, int *first, int *second)
{
  int i;
  if (array == NULL && first == NULL && second == NULL && size < 2) return 0;
  
  *first = a[0];
  for (i = 1; i < size; i++) 
  {
     if (*first <= a[i]) 
     {
        *second = first;
        *first = a[i];
     }
  }
}

- Anonymous June 18, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int two_max (int *array, int size, int *first, int *second)
{
  int i;
  if (array == NULL && first == NULL && second == NULL && size < 2) return 0;
  
  *first = a[0];
  for (i = 1; i < size; i++) 
  {
     if (*first <= a[i]) 
     {
        *second = first;
        *first = a[i];
     }
  }
  return 1;
}

- Anonymous June 18, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is wrong. For the input [25, 2, 77, 50], output is
first = 77
second = 25

whereas it should be
first = 77
second = 50

- avatar June 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int two_max (int *array, int size, int *first, int *second)
{
  int i;
  if (array == NULL && first == NULL && second == NULL && size < 2) return 0;
  
  *first = a[0];
  for (i = 1; i < size; i++) 
  {
     if (*first <= a[i]) 
     {
        *second = first;
        *first = a[i];
     }
  }
  return 1;
}

- Annon June 18, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int two_max (int *array, int size, int *first, int *second)
{
int i;
if (array == NULL && first == NULL && second == NULL && size < 2) return 0;

*first = a[0];
for (i = 1; i < size; i++)
{
if (*first <= a[i])
{
*second = first;
*first = a[i];
}
else if(*second <= a[i])
{
*second = a[i];
}
}
return 1;
}

- Karthik September 23, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int two_max (int *array, int size, int *first, int *second)
{
int i;
if (array == NULL && first == NULL && second == NULL && size < 2) return 0;

*first = a[0];
for (i = 1; i < size; i++)
{
if (*first <= a[i])
{
*second = first;
*first = a[i];
}
else if(*second <= a[i])
{
*second = a[i];
}
}
return 1;
}

- Karthik September 23, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void computeMaxnSecondMax(int* arr, int* max, int* secondMax)
{
	int i = 0;
	if(arr[0]>arr[1])
	{
		*secondMax = arr[1];
		*max = arr[0];
	}
	else
	{	*secondMax = arr[0];
		*max = arr[1];
	}	
	for(i=2;i<6;i++)
	{
		if(arr[i]>*max)
		{
			*secondMax = *max;
			*max = arr[i];
		}		
		else if(arr[i]>*secondMax)
		{
			*secondMax = arr[i];
		}
	}
}

- Anon October 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I came up with some simple logic like this. It works for the arrays which I tested.

uint32_t main(void)
{
    //uint32_t array[10] = {1,2,3,4,5,6,7,8,9,10};
	//uint32_t array[10] = {10,9,8,7,6,5,4,3,2,1};
	uint32_t array[10] = {5,3,6,1,0,8,11,4,4,10};
	
	uint32_t largest[2] = {0};
	uint32_t loopVar = 0;
	
	printf("The Input Array is\n");
	for(loopVar = 0; loopVar < 10; loopVar++){
	   printf("%d \t",array[loopVar]);
	}
	
	for(loopVar = 0; loopVar < 10; loopVar++){
	   if (array[loopVar] > largest[0]){
	      largest[1] = largest [0];
		  largest[0] = array[loopVar];
	   }
	   else if (array[loopVar] > largest[1]){
	      largest[1] = array[loopVar];
	   }
	}
	
	for(loopVar = 0; loopVar < 2; loopVar++){
	   printf("\n%d \t",largest[loopVar]);
	}
    return 0;
}

- Akhil June 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