ADP Interview Question for Developer Program Engineers


Country: United States
Interview Type: In-Person




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

two pass solution
first from left to right , then right to left

public int findMaxPositiveFrequency (int [] frequency){
		int [] left = new int [frequency.length] ;
		int max = 0 , min_so_far = frequency[0] ;
		for (int i = 1 ; i < frequency.length ; ++i) {
			if (frequency[i] < min_so_far) {
				left[i] = max ;
				min_so_far = frequency[i] ;
			} else {
				max = Math.max(max, frequency[i] - min_so_far) ;
				left[i] = max ;
			}
		}
		int [] right = new int [frequency.length] ;
		max = 0 ;
		int max_so_far = frequency[frequency.length - 1] ;
		for (int i = frequency.length -2 ; i >= 0 ; --i) {
			  if (frequency[i] > max_so_far) {
				  right[i] = max ;
				  max_so_far = frequency[i] ; 
			  } else {
				  max = Math.max(max, max_so_far - frequency[i]) ;
				  right[i] = max ;
			  }
		}
		max = 0 ;
		for (int i = 0 ; i < frequency.length ; ++i) {
			max = Math.max(max, left[i] + right[i]) ;
		}
		
		return max ;
	}

- Scott August 11, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

brilliant code , can you explain your approach please ? I mean what was thee intuition behind the logic ?

- gagan September 08, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hey scott , plz do give explanation when you can .

- gagan September 10, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

thanks its working fine

- Anonymous August 11, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

thanks its working fine

- Anonymous August 11, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

thanks its working fine

- Sarath August 11, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

thanks its working fine

- Sarath August 11, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class FindMaxFreq {

	public static void main(String[] args) {
		int arr[] = {2,30,15,10,8,25,80};
		findTopTwoFreqDiff(arr);
	}
	
	public static void findTopTwoFreqDiff(int arr[])
	{
		int tempArr[] = new int[arr.length];
		tempArr[0] = 0;
		for (int i=1; i < arr.length; i++)
		{
			for (int j=0; j < i ; j++)
			{
				if (arr[i]> arr[j])
				{
					tempArr[i] = tempArr[j] +  arr[i]-arr[j];
				}
				else
				{
					tempArr[i]=0;
				}
			}
		}
		
		int firstMax;  
		int secondMax;
		if (tempArr[0] > tempArr[1])
		{
			firstMax = tempArr[0];
			secondMax = tempArr[1];
		}
		else
		{
			firstMax = tempArr[1];
			secondMax = tempArr[0];
		}
		
		for(int i=2; i< tempArr.length; i++)
		{
			if (firstMax < tempArr[i])
			{
				secondMax = firstMax;
				firstMax = tempArr[i];
				
			}
			else
			{
				secondMax = Math.max(secondMax, tempArr[i]);
			}
		}
		
		System.out.println("First Max :" + firstMax + " second max :"+ secondMax);
		
		System.out.println("Max Frequency = " + (firstMax + secondMax) );
	}
}

- Krish August 11, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hi , Guys
Can any body tell me what is the problem with below code as its working fine for most of the test cases but not for all..:(



import java.util.Arrays;

public class PositiveFrequencyFinder {

public static int maximumPositiveFrequency(int[] input1,int input2)
{
//creating new array for storing all positive frequency difference

int positiveFreqDiff[] = new int[input2];
boolean isFreqDiffPositive = false;
int freqSum = 0, j = 0, i = 0;
do {

if (i < (input2 - 1) && input1[i + 1] > input1[i]) {
isFreqDiffPositive = true;
freqSum = freqSum + (input1[i + 1] - input1[i]);
continue;
} else {
if (isFreqDiffPositive) {
positiveFreqDiff[j++] = freqSum;
}
freqSum = 0;
}

}
while (i++ < (input2 - 1));
Arrays.sort(positiveFreqDiff);
return (positiveFreqDiff[input2 - 1] + positiveFreqDiff[input2 - 2]);

}


public static void main(String[] args) {

int input1[]={2,30,15,10,8,25,80};
System.out.println("maximumPositiveFrequency(input1, 7)"+maximumPositiveFrequency(input1, 7));
}




}

- Kanhaiya August 15, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I question is copied from Code Gladiator coding context
Please try it on own because next round is tough.

- Developer April 01, 2016 | 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