## Amazon Interview Question for SDE1s

Country: India
Interview Type: Written Test

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

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

4*underroot(N)

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

solve for k^3 - k^2 = n where n is the number of apples. return 4k.

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

``````// Returns Perimeter Value Necessary to Have N Apples Inside the Plot
public int applesPerimeter(int N) {
int p;
// Handle Even N
if (N % 2 == 0) {
p = (N / 2);
return p * 4;
// Handle Odd N
} else {
p = (N / 2);
return (p * 4) + 2;
}
}``````

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

public int findPerimeter(int n) {

// accumulator
int accumulator = 0;

// side
int side = 0;

// loop while counter < number of apples
while (accumulator < n) {

// add one unit to side
side++;

// each time you add 1 unit to the side, you add:
// 2*side apples +
// 2*(2*side -1) apples + 2*(2*side -2) apples... + 2*(side) apples

// update accumulator with 2*side
accumulator = accumulator + 2*side;

// loop from 2*side-1 to side
int i=side*2 - 1;

while(i>=side) {

// update accumulator
accumulator = accumulator + 2*i;

// subtract counter
i--;
}

}

// return the perimeter = 4 * side
return 4*side;
}

}

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

``````public int findPerimeter(int n) {

// accumulator
int accumulator = 0;

// side
int side = 0;

// loop while counter < number of apples
while (accumulator < n) {

// add one unit to side
side++;

// each time you add 1 unit to the side, you add:
// 2*side apples +
// 2*(2*side -1) apples + 2*(2*side -2) apples... + 2*(side) apples

// update accumulator with 2*side
accumulator = accumulator + 2*side;

// loop from 2*side-1 to side
int i=side*2 - 1;

while(i>=side) {

// update accumulator
accumulator = accumulator + 2*i;

// subtract counter
i--;
}

}

// return the perimeter = 4 * side
return 4*side;
}

}``````

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.