Interview Question for Quality Assurance Engineers


Country: India




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

public class CircularArray {
	private int[] arr;
	private int size;
	private int capacity;
	private int startIndex;
	private int endIndex;
	
	public CircularArray(int size)
	{
		arr = new int[size];
		this.size = size;
		startIndex = 0;
		endIndex = 0;
		capacity = 0;
	}
	
	public boolean enqueue(int val)
	{
		if(capacity == size) return false;
		capacity++;
		arr[endIndex] = val;
		endIndex = (endIndex + 1) % size;
		return true;
	}
	
	public int dequeue() throws IllegalStateException
	{
		if(capacity == 0) throw new IllegalStateException("Queue is empty");
		capacity--;
		int idx = startIndex;
		startIndex = (startIndex + 1) % size;
		return arr[idx];
	}
}

- avico81 January 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Is this thread safe?

- Kaede January 28, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Are you reading the questions at all ? "Make it thread safe" - where is thread safe in your code.

- m@}{ January 28, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

good one

- neeraj May 14, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

If you want to get call from Groupon, write your own code. This will never help you out.

- -Groupon January 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Queue {

private String[] array = null;
private int start = 0;
private int end = -1;
static private int currSize = 0;
static private boolean isDataAdded = false;
private int queueSize = 0;

public Queue(int size){
this.array = new String[size];
this.queueSize = size;
}

public synchronized void enQueue(String data) throws InterruptedException{
if(currSize >= this.queueSize){
System.out.println("queue is full to enQueue "+Thread.currentThread().getName()
+" is blocked till queue will get deQueue'd");
this.wait();
}else if(currSize <= this.queueSize){
this.end ++;
this.array[this.end] = data;
currSize ++;
isDataAdded = true;
System.out.println(data+" added to queue by "+Thread.currentThread().getName());
this.notify();
}
}

public synchronized String deQueue() throws InterruptedException {
String queueData = null;
if(currSize <= 0){
System.out.println("queue is empty to deQueue "+Thread.currentThread().getName()
+" is blocked till queue will get enQueue'd");
this.wait();
}else if(currSize > 0){
queueData = array[start];
array[start] = null;
if(isDataAdded){
this.end = ((this.start == 0) ? -1 : this.end);
isDataAdded = false;
}
this.start++;
currSize--;
if(this.start >= this.queueSize || currSize == 0){
this.start = 0;
this.end = -1;
}
this.notify();
System.out.println(queueData+" removed from queue by "+Thread.currentThread().getName());
}

return queueData;
}
}

- Anonymous July 17, 2013 | 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