Motorola Interview Question for Android Engineers


Country: Brazil
Interview Type: Phone Interview




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

{
}

- Anonymous November 09, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class Node{
	Node next=null;
	int data;
	public Node(int data){
		this.data=data;
	}
	if(Node == null) return null;
	while(Node != null){
	Node n = new Node(data);
	n = this.data;
	}
	add(data);
	remove(Node x);
	insert(data);
	delete(data);
}
public void add(data d){
	while(n.next != null){
		n.next = this.data;
	}
}
public int remove(node x){
	while(n.next != null){
	 if(n.node == x.node){
		n.next.node = n.next.next.node;
	 }
	}
}
public void delete(data){
	while(n.next != null){
		if( n.next.data == data){
		n.next.data = n.next.next.data;
	}
	}
}
public void insert(data){
	while(n.next == null){
		n.next = data;
}
}
}

- Arun December 12, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class LinkedList {
    private Node firstNode;
    private Node lastNode;
    private int size = 0;

    public void add(Object o) {
        Node newNode = new Node(o);
        if (firstNode == null) {
            firstNode = newNode;
            lastNode = newNode;
        } else {
            lastNode.nextNode = newNode;
            lastNode = newNode;
        }
        size++;
    }

    public boolean remove(Object o) {
        Node nextNode = firstNode;
        Node previousNode = null;
        while (nextNode != null) {
            if (nextNode.o == o) {
                removeNode(previousNode, nextNode);
                return true;
            }
            previousNode = nextNode;
            nextNode = nextNode.nextNode;
        }
        return false;
    }

    private void removeNode(Node previousNode, Node nextNode) {
        if (nextNode == firstNode) {
            firstNode = nextNode.nextNode;
        }
        if (nextNode == lastNode) {
            lastNode = previousNode;
        }
        if (previousNode != null) {
            previousNode.nextNode = nextNode.nextNode;
        }
        size--;
    }

    public boolean insert(int index, Object o) {
        if (index < 0 || index > size) {
            return false;
        }
        Node currentNode = null;
        int insertIndex = 0;
        while (insertIndex <= index) {
            if (insertIndex++ == index) {
                return insertNode(currentNode, new Node(o));
            }
            currentNode = currentNode == null ? firstNode : currentNode.nextNode;
        }
        return false;
    }

    private boolean insertNode(Node currentNode, Node insertNode) {
        if (size == 0 || currentNode == null) {
            //add node to the end of list
            add(insertNode.o);
            return true;
        } else {
            if (currentNode == lastNode) {
                lastNode = insertNode;
            }
            insertNode.nextNode = currentNode.nextNode;
            currentNode.nextNode = insertNode;
            size++;
            return true;
        }
    }

    private class Node {
        private final Object o;
        public Node nextNode;

        public Node(Object o) {
            this.o = o;
        }
    }
}

- Andrey Volynets March 21, 2017 | 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