Brossh Interview Question for Developer Program Engineers


Country: Isreal
Interview Type: Written Test




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

Search google for "doubly linked list in c", doubly linked list is quite commonly asked question.
the one from tutorials point is good enough and quite exhaustive.
ignore functions you don't need and comments

- PeyarTheriyaa December 10, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I implemented a simple double linked list in Python:

class Node:
    def __init__(self, value=None, left=None, right=None):
        self.value = value
        self.left = left
        self.right = right

    def append(self, value):
        if self.right is not None:
            self.right.append(value)
        else:
            self.right = Node(value, self)

    def remove(self, value):
        if self.value == value:
            if self.left is not None:
                self.left.right = self.right
            else:
                self.value = self.right.value
                self.right = self.right.right
                self.right.left = self

        if self.right is not None:
            self.right.remove(value)

    def as_list(self):
        ret_list = list()
        Node._as_list(self, ret_list)
        return ret_list

    @staticmethod
    def _as_list(node, ret_list):
        ret_list.append(node.value)
        if node.right is not None:
            Node._as_list(node.right, ret_list)


class DLinkedList:
    def __init__(self, numbers_list=None):
        self.root = DLinkedList._generate_nodes(numbers_list if numbers_list is not None else [])

    @staticmethod
    def _generate_nodes(numbers_list):
        if len(numbers_list) == 0:
            return None

        root = None
        for number in numbers_list:
            if root is None:
                root = Node(number)
            else:
                root.append(number)

        return root

    def as_list(self):
        if self.root is None:
            return []

        return self.root.as_list()

    def remove(self, element):
        if self.root is None:
            return

        return self.root.remove(element)


dlinked_list = DLinkedList([1, 2, 43, 1, 56, 12, 5, 1, -2, 4333, 3])
print(dlinked_list.as_list())
dlinked_list.remove(43)
print(dlinked_list.as_list())
dlinked_list.remove(1)
print(dlinked_list.as_list())

- Practitioner December 11, 2018 | 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