Samsung Interview Question for Software Engineer Interns


Team: Android
Country: United States
Interview Type: Phone Interview




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

The last line should be

return [max(a,c), min(b,d)]

- Westlake January 29, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

with JavaScript (you can copy it into your browser console (F12) to try it out)

// some ranges
var intRangeA = [10, 100];
var intRangeB = [60, 150];
var intRangeC = [120, 200];
var intRangeD = [170, 200];
var ranges = [intRangeA, intRangeB, intRangeC, intRangeD];
// sort function
var numSort = function(a, b) {
	return b - a;
};
// loop over ranges
for (var i = 0; i < ranges.length; i++) {
	for (var j = 0; j < ranges.length; j++) {
		if (i != j) {
			var sortA = ranges[i].sort(numSort);
			var sortB = ranges[j].sort(numSort);

			var maxA = sortA[0];
			var minA = sortA[sortA.length - 1];
			var maxB = sortB[0];
			var minB = sortB[sortB.length - 1];

			if (minA <= minB && maxA <= maxB) {
				var diff = maxA - minB;
				if (diff > -1) {
					console.debug("Overlap found([" + ranges[i].sort(numSort).reverse() + "];[" + ranges[j].sort(numSort).reverse() + "]), with overlapping range:" + minB + ";" + maxA);
				}
			}

		}
	}
}

- Anonymous February 17, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Interger ranges (x1,x2) and (y1,y2)

int overlap(int x1,int x2,int y1,int y2){
	if(x2>=y1 && x1<=y2)
		return ((Math.max(x2,y2) - Math.min(x1,y1))-(Math.abs((x2-y1)-(y2-x1)));
	else
		return -1;
}

- sumeet.mahajan86 May 22, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

check if 2 ranges [a,b] and [c,d] overlap

if (b < c || d < a) 
    return emtpy;
    
return [min(a,c), min(b,d)]

- Anonymous January 29, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 votes

The OVERLAPPED range should be [max(a,c), min(b,d)]

I guess it was a typo for you.

- chriscow January 29, 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