Oracle Interview Question for Financial Software Developers


Country: India
Interview Type: In-Person




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

we can implement the queue using two stacks..for adding we can pop the stack and put it in another stack...that will reverse the stack...now we can push the new element on the second stack and then we can pop the entire stack back into the first stack....for deleting from front we can simply....push in the stack.

- Anonymous February 09, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 vote

public class QueueUsingStack {
	Stack<Integer> q1 = new Stack<Integer>();
	Stack<Integer> q2 = new Stack<Integer>();

	public void pop() {

		while (q1.size() > 1)
			q2.add(q1.pop());

		System.out.println("POPped:" + q1.pop());

		while (!q2.isEmpty())
			q1.add(q2.pop());

	}

	public void push(int val) {
		System.out.println("PUSHed:" + val);
		q1.add(val);

	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		QueueUsingStack suq = new QueueUsingStack();
		suq.push(5);
		suq.push(4);
		suq.push(3);
		suq.push(2);
		suq.push(1);

		suq.pop();
		suq.push(6);
		suq.pop();
		suq.pop();
		suq.pop();

	}

}

- Anonymous March 16, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream> 
#include<stack> 
using namespace std; 
  
/* STRUCTURE OF QUEUE HAVING TWO STACKS */
struct _queue 
{ 
    stack<int> s1; 
    stack<int> s2; 
}; 
  
/* FUNCTION TO ENQUEUE AN ITEM TO QUEUE */
void enQueue(_queue* q1, int x) 
{ 
    q1->s1.push(x); 
} 
  
/* FUNCTION TO DEQUEUE AN ITEM FROM QUEUE */
int deQueue(_queue* q1) 
{ 
    int ele=0; 
    if(q1->s1.empty() && q1->s2.empty()) 
    { 
        printf("Error"); 
        exit(0); 
    } 
    if(q1->s2.empty()) 
    { 
        while(!q1->s1.empty()) 
        { 
            int temp=q1->s1.top(); 
            q1->s1.pop(); 
            q1->s2.push(temp); 
        } 
    } 
    ele=q1->s2.top(); 
    q1->s2.pop(); 
      
    return ele; 
} 
  
/* DRIVER FUNCTION TO TEST ANOVE FUNCTIONS */
int main() 
{ 
   /* CREATE A QUEUE WITH ITEMS 1 2 3*/
   _queue *q = new _queue; 
   enQueue(q, 1); 
   enQueue(q, 2); 
   enQueue(q, 3);     
    
   /* DEQUEUE ITEMS */
   printf("%d  ", deQueue(q)); 
   printf("%d  ", deQueue(q)); 
   printf("%d  ", deQueue(q));   
    
   return 0; 
}

- Pan Go July 01, 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