VMWare Inc Interview Question for Member Technical Staffs


Country: United States
Interview Type: Phone Interview




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

Circular queue using array:
Initialize head and tail to -1 and set buffer_size in the constructor
count is the variable to track the number of elements added to the queue. Since its shared by both enqueue and dequeue functions, we need to synchronize the methods to be thread safe.

public synchronized void enQueue(int item){
			if(count == buffer_size){
				System.out.println("Queue is full!!");
			}
			else{
				tail++;
				tail = tail % buffer_size;
				queueArray[tail] = item;
				count++;
			}
	}

- Usha Vijay July 26, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Maybe we should acquire lock of queueArray[tail], not this, like in blocking queue. Because locking on this prevent any operations with queue.

- Gleb July 26, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Ya. We can use synchronize block instead. Like

synchronized (queueArray)
    {
       tail = tail++ % buffer_size;
	queueArray[tail] = item;
	count++;
  }

- Usha Vijay July 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Obviously it is a blocking queue

public synchronized void enQueue(int item){
if(count == buffer_size){
wait();
}
else{
queueArray[tail] = item;
tail = tail++ % buffer_size;
count++;
notifyAll();
}
}

- yifeisun1987 October 12, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int front, rear;

public synchronized void enqueue(int A[], int x) {
	if (front == rear == -1) {
		A[front = rear = 0] = x;
	} else if ((rear + 1) % n != front) {
		A[rear = (rear + 1) % n] = x;
	} else {
		printf("Queue Overflowed!");
}

- Suren September 23, 2014 | 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