Amazon Interview Question for SDE-2s


Country: United States
Interview Type: Phone Interview




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

Can you please give the explanation of this question clearly

- Anonymous September 02, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Could you please elaborate on what order the integers are visited.

- divm01986 September 02, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class UDLinkedList {

    private Node head;

    public UDLinkedList(Node node) {
        head = node;
    }

    public static void main(String[] args) {
        Node head = new Node(1);
        head.next = new Node(2);
        head.next.next = new Node(3);
        head.next.next.next = new Node(4);
        head.down = new Node(6);
        head.down.next = new Node(7);
        head.down.next.next = new Node(10);
        head.down.next.down = new Node(8);
        head.down.next.down.next = new Node(9);
        head.down.next.next.down = new Node(11);
        head.down.next.next.down.next = new Node(12);
        UDLinkedList list = new UDLinkedList(head);
        UDLLIterator iterator = list.iterator();
        try {
            while (iterator.hasNext()) {
                System.out.println(iterator.next());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public UDLLIterator iterator() {
        return new UDLLIterator();
    }

    private static class Node {
        private int value;
        private Node next;
        private Node down;

        public Node(int v) {
            this.value = v;
        }
    }

    private class UDLLIterator {

        private Stack<Node> stack;

        public UDLLIterator() {
            stack = new Stack<>();
            stack.push(head);
        }


        public boolean hasNext() {
            return !stack.isEmpty();
        }


        public int next() throws Exception {
            if (hasNext()) {
                Node current = stack.pop();
                if (current.next != null) {
                    stack.push(current.next);
                }

                if (current.down != null) {
                    stack.push(current.down);
                }
                return current.value;
            } else {
                throw new Exception("No element to iterate over");
            }
        }
    }
}

- rsrs3 September 02, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

please explain the question!!!

- hsamogh January 05, 2016 | 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