Adobe Interview Question for Testing / Quality Assurances


Country: United States
Interview Type: Phone Interview




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

int secondMaxEle(int a[], int len) {
    int max = INT_MIN, secondMax = INT_MIN, i;
    for(i = 0; i < len; i++) {
        if(a[i] > max) {
            secondMax = max;
            max = a[i];
        }
        else if(a[i] > secondMax && a[i] < max)
            secondMax = a[i];
    }
    return secondMax;
}

- cooldaa January 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public int secondMaxElem(int[] ary}
{
if (ary == null || ary.size == 0 || ary.size == 1) return ERROR;

int max[] = new int[2];
max[0] = a[0]; max[1] = a[1];
for (int i = 2; i < ary.size; i++)
{
if (ary[i] > max[0] || ary[i] > max[1]
{
max[0] < max[1] ? max[0] = ary[i] : max[1] = ary[i];
}
}
return max[0] < max[1] ? max[0] : max[1];
}

- sd January 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

why not array.size<=1 return ERROR

- anonymous January 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

if the interviewer ask u to extend the code to get the Kth of that array,what will u do?

- anonymous January 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

use heap to extend..

- abhishekatuw January 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

usage of heap will destroy the basic premise of "Single Loop".

- Anonymous January 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is the stupidest code segment I've ever seen!

int max[] = new int[2];
max[0] = a[0]; max[1] = a[1];
for (int i = 2; i < ary.size; i++)

really??

- codemonkey February 20, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int secondMaxEle(int a[], int len) {
    int max = a[0], secondMax = a[0];
    for(int i = 1; i < len; i++) {
        if(a[i] > max) {
            secondMax = max;
            max = a[i];
        }
        else if(a[i] > secondMax)
            secondMax = a[i];
    }
    return seconMax;
}

- cooldaa January 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

{5,4,3,2,1} return will be 5....

- Anonymous January 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

{5,4,3,2,1} return will be 5....

- Anonymous January 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Thanks for pointing the bug. The correction is that I initialize both max and secondMax to the lowest possible integer value and then traverse the loop from the first element.

int secondMaxEle(int a[], int len) {
    int max = INT_MIN, secondMax = INT_MIN, i;
    for(i = 0; i < len; i++) {
        if(a[i] > max) {
            secondMax = max;
            max = a[i];
        }
        else if(a[i] > secondMax && a[i] < max)
            secondMax = a[i];
    }
    return secondMax;
}

- cooldaa January 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Failing in case of arr[] = {1,1};

- Devesh January 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Failing in case of arr[] = {1,1};

- Devesh January 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

What is the complexity??

- Anonymous April 20, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

if there is duplicate max value in an array, the second largest will be the same with the max

- amor89813 March 27, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int a[5]={2,5,4,6,7};
    int i,j;
    
    for(i=0;i<5;i++)
    {
                    int j=i+1;
             if(a[i]>a[j]){
                           int temp=a[j];
                           a[j]=a[i];
                           a[i]=temp;       
                    
                    }
                    }
pf("%d",a[1]);

- arun kumar January 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int len=100;
int a[len] = {3,7,8,2,9}
int max=a[0], smax=a[1];

//Getting max & second max between first 2 numbers
if(a[0]<a[1])
{
temp = smax; //maximum number
smax=a[1]; //second max number
max=temp;
}
//Comparing max, smax & swapping it when required in a loop
for(i=2;i<len;i++)
{
    if(a{i}>max)
    {    
           smax=max;   //bcoz max is already greater than smax
           max=a[i];
    }
    else if(a[i]>smax)
    {
     smax=a[i];
     }
}

- rajesh.savvy February 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<stdlib.h>
int select(int a[],int left,int right,int k)
{
if(left>=right) return a[left];
int i=left+1;
int j=right;
int p=a[left];
int t;
while(j>=i)
{
while(a[i]>p)i++;
while(a[j]<p)j--;
if(i>=j)break;
else{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
if(j-left+1==k)
return p;
t=a[left];
a[left]=a[j];
a[j]=t;
if(j-left+1<k)
return select(a,j+1,right,k-j+left-1);
else
return select(a,left,j-1,k);
}
int main() {
int a[20],k,n,i,d;
printf("Enter no of elements\n");
scanf("%d",&n);
printf("Enter n elements\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter the value of k\n");
scanf("%d",&k);
d=select(a,0,n-1,k);
printf("Kth largest element is %d\n",d);
return 0;
}

- narayan kunal March 05, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Second_largest {
public static void main(String[] args) {
int array[]={5,4,3,2,1};
int max1=array[0];
int max2=array[1];
if(array.length<2){
System.out.println("not able to find second largest number");
}
else{
for(int i=1;i<array.length;i++){
if(array[i]>max1){
max2=max1;
max1=array[i];
}

}
System.out.println(max2);}
}

- Anonymous July 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

sorry mistake on above code
public class Second_largest {
public static void main(String[] args) {
int array[]={1,2};
if(array.length<2){
System.out.println("not able to find second largest number");
return;
}
int max1=array[0];
int max2=array[1];


for(int i=1;i<array.length;i++){
if(array[i]>max1){
max2=max1;
max1=array[i];
}

}
System.out.println(max2);
}

}

- Anonymous July 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In a given array if you are trying to get the nth largest element.

Than take the nth node from the last as pivot element and than apply the partition logic of quick sort. which will get the nth element from the last in place. Left subarray (unsorted) will be the values less than the element and right subarray(unsorted) will be the values greater than the element.
But you will get the nth largest element from the last in the array. :)

- Reev September 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int len = 12;

int a[] = {2,183,8,2,1,91,23,100,4,2,52,530};
int max=a[0], smax=a[1];
int temp,i;


//Getting max & second max between first 2 numbers
if(a[0]<a[1])
{
temp = smax; //maximum number
smax=a[0]; //second max number
max=temp;
}

printf("%d\n",max);
printf("%d\n",smax);

//Comparing max, smax & swapping it when required in a loop
for(i=2;i<len;i++)
{
if(a[i] > max)
{
smax=max; //bcoz max is already greater than smax
max=a[i];
}
else if(a[i]>smax)
{
smax=a[i];
}
printf("%d\n",max);
printf("%d\n",smax);
}

printf("%d",smax);

- mani November 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

// C#
// This code should look after duplicate values and minimum array size.

Sample array {0, -1, -3, -1, 0} after it's sorted {-3,-1,-1,0,0}

Answer = 0;

public void SecondLargest(int[] nums)
{

if (nums.Length < 2) Console.Write("invalid input");

int secondMax=nums[0], max=nums[0];

for (int i=0; i < nums.Length; i++)
{
if (nums[i]>secondMax) secondMax=nums[i];

if (secondMax > max)
{

int temp = max;
max = secondMax;
secondMax = temp;

} //end if

} //end for loop

Console.Write("Second Largest Number: {0}", secondMax);

} //end method

- no body June 15, 2014 | 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