## Amazon Interview Question for Quality Assurance Engineers

Team: Kindle
Country: India
Interview Type: Written Test

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

The first method is just to simply go through the array and calculate the sums for all previous elements and all next elements, and compare them.
But is is too inefficient.
More efficient method is:
1). To calculate total sum of all elements.
Growing Sum =0
2). Going through the array, subtract elements from the total sum and add them to growing sum. Compare Growing Sum to the Total Sum. If they are equal - we found our element(s).

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

Example given in question is wrong. Please rectify that to avoid any confusion.

1+0==1
but -11 +1 +12 !=1

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

``````var list = new List<int>() {1, 1, -11, 1, 12};
var getListCount = list.Count;
var isListCountOdd = getListCount % 2 == 0;
var getIntegerIncrement = 3;
int takeFromList;

if (isListCountOdd)
{
takeFromList = getListCount/2;
}
else
{
if (getListCount <= 5)
{
takeFromList = getListCount - getIntegerIncrement;
}
else
{
getIntegerIncrement++;
takeFromList = getListCount - getIntegerIncrement;
}
}

// Get left and right numbers
var leftNumbers = list.Take(takeFromList);
var rightNumbers = list.Skip(takeFromList).Take(getIntegerIncrement);
// Sum them up
var leftNumbersTotal = leftNumbers.Sum();
var rightNumbersTotal = rightNumbers.Sum();

Console.Write(leftNumbersTotal == rightNumbersTotal ? "Left == Right" : "Left != Right");

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

``````-- This solution is for list contains 4 or more count.
var list = new List<int>() {1, 1, -11, 1, 12};
var getListCount = list.Count;
var isListCountOdd = getListCount % 2 == 0;
var getIntegerIncrement = 3;
int takeFromList;

if (isListCountOdd)
{
takeFromList = getListCount/2;
}
else
{
if (getListCount <= 5)
{
takeFromList = getListCount - getIntegerIncrement;
}
else
{
getIntegerIncrement++;
takeFromList = getListCount - getIntegerIncrement;
}
}

// Get left and right numbers
var leftNumbers = list.Take(takeFromList);
var rightNumbers = list.Skip(takeFromList).Take(getIntegerIncrement);
// Sum them up
var leftNumbersTotal = leftNumbers.Sum();
var rightNumbersTotal = rightNumbers.Sum();

Console.Write(leftNumbersTotal == rightNumbersTotal ? "Left == Right" : "Left != Right");

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

PYTHON::

>>> def sum(l):
a = 0
d = 0
b = len(l)
c = b/2
for i in range(0, c):
a = a + l[i]
for j in range(c, ((c*2)+1)):
d = d + l[j]
if a == d:
print "both sides of sum is equal"
return a
elif a != d:
a = 0
d = 0
for i in range(0, c+1):
a = a + l[i]
for j in range(c+1, ((c*2)+1)):
d = d + l[j]
if a == d:
print "both sides of sum is equal at 2nd level"
return a
else:
print "both sides of sum is not equal"
return False

>>>
>>> sum([1,1,-11,1,12])
both sides of sum is equal
2
>>> sum([-11,1,12,1,1])
both sides of sum is equal at 2nd level
2
>>> sum([-11,1,12,1,0])
both sides of sum is not equal
False
>>>

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

``````public static void main(String[] args) {
int[] a = {1,0,1,12,-2,-8};
int sum1 = 0, sum2 = 0;

for(int i=1; i<a.length; i++) {
for(int j = 0; j<=i; j++) {
sum1 += a[j];
}

for(int k=i+1; k<a.length; k++) {
sum2 += a[k];
}
if(sum1 == sum2) {
System.out.println("Sum1: " + sum1);
for(int l =0; l<=i; l++) {
System.out.println(a[l]);
}
System.out.println("Sum2: " + sum2);
for(int l =i+1; l<a.length; l++) {
System.out.println(a[l]);
}
}
sum1 =0; sum2 = 0;
}
}``````

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

``````protected void findLeftAndRightSum(){
//int[] a = {1,0,1,12,-2,-8};
int[] a = {1, 1, -11, 1, 12};
int sum1 = 0, sum2 = 0, index = 0;

while(index<a.length){
sum1 = 0;
sum2 = 0;
for(int i=0; i<=index; i++){
sum1 = sum1+a[i];
}
for(int i=index+1; i<a.length; i++){
sum2 = sum2+a[i];
}
if(sum1==sum2){
break;
}else{
index++;
}
}
System.out.println("Common Sum : " + sum1);
}``````

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

``````protected void findLeftAndRightSum(){
//int[] a = {1,0,1,12,-2,-8};
int[] a = {1, 1, -11, 1, 12};
int sum1 = 0, sum2 = 0, index = 0;

while(index<a.length){
sum1 = 0;
sum2 = 0;
for(int i=0; i<=index; i++){
sum1 = sum1+a[i];
}
for(int i=index+1; i<a.length; i++){
sum2 = sum2+a[i];
}
if(sum1==sum2){
break;
}else{
index++;
}
}
System.out.println("Common Sum : " + sum1);``````

}

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

protected void findLeftAndRightSum(){
//int[] a = {1,0,1,12,-2,-8};
int[] a = {1, 1, -11, 1, 12};
int sum1 = 0, sum2 = 0, index = 0;

while(index<a.length){
sum1 = 0;
sum2 = 0;
for(int i=0; i<=index; i++){
sum1 = sum1+a[i];
}
for(int i=index+1; i<a.length; i++){
sum2 = sum2+a[i];
}
if(sum1==sum2){
break;
}else{
index++;
}
}
System.out.println("Common Sum : " + sum1);
}

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

``````private static boolean recArray ( int[] nums, int index, int sum1, int sum2 ) {
if ( index >= nums.length ) {
return sum1 == sum2;
}
int value = nums[index];
return (recArray(nums, index + 1, sum1 + value, sum2) || recArray(nums, index + 1, sum1, sum2 + value));
}``````

where index =0 at the beginning

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.

### 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.