Amazon Interview Question for SDETs


Country: United States
Interview Type: Phone Interview




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

class Stack:
def __init__(self):
self.items = []

def isEmpty(self):
return self.items == []

def push(self, item):
self.items.append(item)

def pop(self):
return self.items.pop()

def peek(self):
return self.items[len(self.items)-1]

def size(self):
return len(self.items)

- data_freak June 07, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package careerUp;

public class Stack {
private int arr[];
private int maxSize;
private int top = -1;
private int bottom = 0;

Stack(int s){
maxSize = s;
arr = new int[maxSize];
top = -1;
}

public void push(int elm){
arr[++top] = elm;
}

public int pop(){
return arr[top--];
}

public int peekArray(){
return arr[top];
}

public boolean isEmpty(){
return (top == -1);
}

public boolean isFull(){
return (top == maxSize-1);
}


public static void main(String args[]){
Stack stack = new Stack(5);
stack.push(10);
stack.push(12);
stack.push(13);
stack.push(15);
stack.push(14);
while(!stack.isEmpty()){
System.out.println(stack.pop());
}

}
}

- codeforstartups June 26, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package careerUp;

public class Stack {
	private int arr[];
	private int maxSize;
	private int top = -1;
	private int bottom = 0;
	
	Stack(int s){
		maxSize = s;
		arr = new int[maxSize];
		top = -1;
	}
	
	public void push(int elm){
		arr[++top] = elm;
	}
	
	public int pop(){
		return arr[top--];
	}
	
	public int peekArray(){
		return arr[top];
	}
	
	public boolean isEmpty(){
		return (top == -1);
	}
	
	public boolean isFull(){
		return (top == maxSize-1);
	}
	
	
	public static void main(String args[]){
		Stack stack = new Stack(5);
		stack.push(10);
		stack.push(12);
		stack.push(13);
		stack.push(15);
		stack.push(14);
		while(!stack.isEmpty()){
			System.out.println(stack.pop());
		}
		
	}
}

- codeforstartups June 26, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package Stack;

public class Stack {

	private int capacity;
	private int[] baseArray;
	private int index = -1;
	private int size = 0;

	public Stack(int capacity) {
		this.capacity = capacity;
		baseArray = new int[capacity];
	}

	public void push(int data)throws StackFullException{
		if(this.isFull()){
			throw new StackFullException("Stack Full  ... Can't push more data");
		}
		baseArray[++index] = data;
		size++;
	}

	public int pop()throws StackEmptyException{
		if(this.isEmpty()){
			throw new StackEmptyException("Stack Empty ... Nothing to pop ");
		}
		size--;
		return baseArray[index--];
	}

	public int peek(){
		return baseArray[index];
	}

	public boolean isEmpty(){
		if(this.size() < 1){
			return true;
		}
		return false;
	}

	public boolean isFull(){
		if(this.size == this.capacity){
			return true;
		}
		return false;
	}

	public int size(){
		return this.size;
	}
}

package Stack;

public class StackImpl {
	public static void main(String[] args) throws Exception{

		Stack stack = new Stack(5);
		
		
		stack.push(10);
		stack.push(20);
		stack.push(30);
		stack.push(40);
		stack.push(50);
		
		
		while(!stack.isEmpty()){
			System.out.println(stack.pop());
		}
		
	}
}

- ultikhopdi July 18, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Isn't a basic array an example of a stack?

- Chris October 27, 2018 | 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