Expedia Interview Question for Software Engineer in Tests


Team: SDET
Country: India
Interview Type: Phone Interview




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

What do you mean by infinite range?

Does that mean that numbers are infinite? or range is infinite?

Looking at the hint (How to implement using boolean array.?), it seems the interviewer implied that the numbers are infinite but range can be limited.

in that case, make a boolean array of length Integer.MAX_VALUE or if given range.
Whenever you receive a number, set that corresponding index to true.

- abcd May 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

When I told to use hashmap she asked me that whether I am considering the numbers in range or not . She told me numbers are infinite .

- zammer May 16, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hi Zammer,

For the boolean array implementation, you could use the values stored in the data structure as indices into your boolean array. For example.

duplicate_arr[arr_size] = false //Initialize all entries of the boolean array to false.

insert_data:
if duplicate_arr[data] = false
data_structure.insert(data)
duplicate_arr[data] = true
else
print("Duplicate value!")

- AB May 16, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

@zammer. what is the key value pair you considered.

- dadakhalandhar May 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If you're trying to find duplicates in an infinite quantity of numbers with infinite range and you can only use a boolean array of finite size, you're going to have a hard time.

If you're allowed to have some small number of errors, I believe the traditional solution for this kind of problem is to use a Bloom filter.

- Mike Lewis May 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

**** ur ques..

- Anonymous September 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

can use set.
else, if want to use boolean array then, make one of size 256 default false. Ture it to true if u encounter the ascii character. check if it was already set to true before then duplication.

- bhavi February 22, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public void getDupInt() {
		Scanner sc = new Scanner(System.in);
		System.out.println("Print a number");
		int range = sc.nextInt();

		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		for (int i = 0; i < range; i++) {
			if (map.containsKey(range)) {
				map.put(i, map.get(i) + 1);
			} else {
				map.put(i, 1);
			}
		}
		Set<Map.Entry<Integer, Integer>> entryset = map.entrySet();
		for (Entry<Integer, Integer> entry : entryset) {
			if (entry.getValue() == 1) {
				System.out.println("unique element " + entry.getKey()
						+ entry.getValue());
			} else
				System.out.println("duplicate element " + entry.getKey()
						+ entry.getValue());
		}
	}

- Khyati Sehgal April 04, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

Assuming the range is limited and numbers are infinite:
1) Find min, max value inside the range
2) declare boolean array of length max-min+1
3) For each number set true in array in this way: arr[num-min] = true. If you the array has been already set then you have duplicate.

- thelineofcode July 18, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What is num in ur answer

- Anonymous February 17, 2014 | Flag


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