Yahoo Interview Question for Software Engineer / Developers


Team: Ad
Country: United States
Interview Type: In-Person




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

Just create your own singly linked list w/ the appropriate (FIFO) pointer?

- $wizzl3 March 20, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

we can use Doubly or singly Linked List

keep a tail pointer and a head pointer

public class Queue<T> {
    private static class Node {
        Node previous;
        Node next;
        T value;
        
        public Node(T value, Node next, Node previous) {
            this.value = value;
            this.next = next;
            this.previous = previous;
        }
    }

    private head = null;
    private tail = null;
    private int size = 0;
    private int maxSize = 0;
    public Queue(int size) {
        this.maxSize = size;
    }
    
    public void insert(T value) {
        if (head == null) {
            head = new Node(value, null, null);
            tail = head;
            size += 1;
        } else {
            if (this.size == this.maxSize) {
                throw new Exception("Queue is full");
            }
            Node tempNode = new Node(value, head, null);
            head.previous = tempNode;
            head = tempNode;
            size += 1;
        }
    }
    
    public T pop() {
        if (this.size < 1) {
            throw new Exception("Queue is empty");
        } else if (size == 1) {
            T value = head.value;
            head = null;
            tail = null;
            size = 0;
            return value;
        }
        Node tempNode = tail;
        tail.previous.next = null;
        tail = tempNode.previous;
        size -= 1;
        return tempNode.value;
    }
}

- byteattack June 01, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.


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