ADP Interview Question for Developer Program Engineers


Country: India
Interview Type: Phone Interview




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

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

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

The question is phrased very strangely; I have no idea what input 2 does and where 2MHz came from, but let's assume we have an array of integers and we want to find the max positive difference across two selections. The easiest way is to sort then


((last - first)) + ((last-1) - (first+1))

int selection1 = -1;
int selection2 = -2;

//Since the array is sorted, we don't need to check if the subtraction operation is +ve (incase of -ve values being allowed)
selection1 = A[A.length-1] - A[0];
selection2 = A[A.length-2] - A[1];
maxDifference = selection1 + selection2;

Insertion sort if the array is very small, mergesort otherwise = O(nlgn)
Comparison operation twice 2 * C
O(nlogn) + 2C

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

package com.concurrency.pkg;

import java.util.Arrays;

public class MaxFrequency {
	private static int[] a = { 2, 30, 15, 10, 8, 25, 80 };

	public static void main(String[] args) {
		Arrays.sort(a);
		System.out.println((a[a.length - 1] - a[0]) + (a[a.length - 2] - a[1]));

	}

}

- Suresh Patel January 03, 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