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 ;
}``````

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

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

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

Hey scott , plz do give explanation when you can .

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

thanks its working fine

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

thanks its working fine

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

thanks its working fine

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

thanks its working fine

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) );
}
}``````

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));
}

}

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.

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.

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.