Expedia Interview Question for Software Engineer / Developers






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

1) sort the array
2) then start with one pointer i=0 and another j=n(array length)
3) calculate sum if greater then k then j-- and if less then k than i++
4) repeat 3 step till you find the sum or i>j

- nileshagarwal10 July 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1) Hash the values in a table 'Table'.
2) For all values 'e_i' in the series
a) if 'K - e_i' is found in the table at position j, return (i, j)
3) return null

- evitagen wercs November 11, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

or sort in (nlogn) then do a binary search .

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

Here's a solution using a hashmap to make the time complexity O(n)

private static void printNumsThatAddUpTo(int[] arr, int target) {
	Map<Integer, Integer> storage = new HashMap<Integer,Integer>();
	for (int i = 0; i < arr.length;i++){
		if ( storage.containsKey(target - arr[i])){
			if (!storage.containsKey(arr[i])){
				System.out.println(arr[i]+ " "+(target - arr[i]));
				storage.put(arr[i], arr[i]);
			}
		}else if (!storage.containsKey(arr[i])){
			storage.put(arr[i], arr[i]);
		}
	}

}

- JDar January 27, 2014 | 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