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

- temp February 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Cant you use binary search if the array is sorted?

- Avinash February 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If array is not sorted --

1. Calculate avg O(n)

- Pritam February 25, 2012 | Flag Reply
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)

- Pritam February 25, 2012 | Flag Reply
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]);
}
}
}

- Barani February 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- santosh.ksingh03 February 21, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

a

- Manish November 13, 2013 | Flag Reply
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) {
                                integerArray.add(arr[index]);
                        }
                }
                
                return  ArrayUtils.toPrimitive((Integer[])integerArray.toArray());
                
        }

- Kapil July 14, 2017 | 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