## Expedia Interview Question

Country: United States

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

We can do in O(2n)
In the first pass you can calculate the sum of the array and get the avg
In the second pass can get the numbers greater than the avg

Is there a better solution for this problem

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

Cant you use binary search if the array is sorted?

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

If array is not sorted --

1. Calculate avg O(n)

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

Sorry last comment submitted accidentally
If array is not sorted --
1. calculate avg O(n)
2. take 2 pointers one from starting and another from end of array
3. based on the condition whether element (from beginning and end) > avg move all end element to the beginning and replace end element -1
4. So overall time complexity O(n), space O(1)

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

This is 0(2n)...not sure if there's a better solution for unsorted array...

public static void checkAvg(int[] a1){
float sum=0;
float avg;
for(int i=0;i<a1.length;i++){
sum=sum+a1[i];
}
avg=(sum/(a1.length-1));
for(int i=0;i<a1.length;i++){
if(a1[i]>= avg){
System.out.println(a1[i]);
}
}
}

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

{{ var sum = arr.Where(x => x > arr.Average());}}

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

a

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

``````Integer[] findIntegers(int[] arr) {

int avg = 0;
for(int index = 0; index < arr.length; index++) {
avg+=arr[index];
}

avg /= arr.length;

ArrayList<Integer> integerArray = new ArrayList<Integer>();
for(int index=0; index < arr.length; index++ ) {
if(arr[index] > avg) {
}
}

return  ArrayUtils.toPrimitive((Integer[])integerArray.toArray());

}``````

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.