Roxar Interview Question for Software Engineer Interns


Country: United States
Interview Type: Phone Interview




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

Assuming all numbers in the set are positive.
Step 1. Add the numbers in the set.
Step 2. Subtract the given sum from added total at step1.
Step 3. Divide number by 2 at step 2. Reverse the sign of this particular number.

- deepshikhaagrl March 17, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

O(n) time, O(1) space

static int reverseSignElement(int[] array, int target) {
		if (array == null || array.length == 0)
			return 0;
		int sum = 0;
		for (int i : array) {
			sum += i;
		}
		for (int i : array) {
			if (sum - 2*i == target)
				return i;
		}
		return 0;
	}

- ikoryf March 17, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

How did you derive the " sum - 2*i "? It clearly works, but logically how did you get there?

- Marcus March 18, 2016 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

logic derivation:

Change of sign a element in set will return the target number.

Assume R is the resultant element and we will change the sign of R

So in the sum of the all elements of set (Say Sum), R is also included. First exclude that.
So we have sum of all elements except R => Sum – R.
Now, we changed sign of R and add it to get new sum of all elements.
( Sum –R ) + ( –R) = target //we changed sign of R
i.e, Sum –R –R = target
i.e, Sum – 2*R = target

Now for which i in set, this equation will satisfy, that is the result.

- ms March 18, 2016 | 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