Brossh Interview Question for Developer Program Engineers

Country: Isreal
Interview Type: Written Test

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

I kinda built a binary tree out of an array and use that to print sorted values

#include <stdio.h>

int arr[100], end = 0;

void insert(int index, int v)
    int tmp, i;
    for (i = index; i < end; i++)
        tmp = arr[i];
        arr[i] = v;
        v = tmp;
    arr[end] = v;

void add(int s, int e, int v)
    if (s == e)
        insert(s, v);
        int mid = (e + s) / 2;
        if (arr[mid] == v)
            insert(mid, v);
        else if (arr[mid] > v)
            add(s, mid, v);
            add(mid + 1, e, v);

void printAsc()
    for (int i = 0; i < end; i++)
        printf("%d ", arr[i]);

void printDes()
    for (int i = end - 1; i >= 0; i--)
        printf("%d ", arr[i]);

int main(int argc, char const *argv[])
    int n, tmp;
    printf("Enter  the limit n : ");
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        printf("Enter number %d : ", i + 1);
        scanf("%d", &tmp);
        add(0, end, tmp);
    printf("\nAscending : ");
    printf("\nDescending : ");
    return 0;

hope this helps

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

I implemented a simple binary search tree in Python:

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

    def add(self, value):
        if value < self.value:
            self.left = Node._add(self.left, value)
        if value >= self.value:
            self.right = Node._add(self.right, value)

        return self

    def _add(node, value):
        if node is not None:
            return node

        return Node(value)

    def sorted(self, order):
        ret_list = list()
        if order >= 0:
            Node._traverse_sort(self, ret_list, Node._traverse_left, Node._traverse_right)
            Node._traverse_sort(self, ret_list, Node._traverse_right, Node._traverse_left)
        return ret_list

    def _traverse_left(node, ret_list, first_go, second_go):
        if node.left is not None:
            Node._traverse_sort(node.left, ret_list, first_go, second_go)

    def _traverse_right(node, ret_list, first_go, second_go):
        if node.right is not None:
            Node._traverse_sort(node.right, ret_list, first_go, second_go)

    def _traverse_sort(node, ret_list, first_go, second_go):
        first_go(node, ret_list, first_go, second_go)
        second_go(node, ret_list, first_go, second_go)

def generate_nodes(numbers_list):
    root = None
    for number in numbers_list:
        if root is None:
            root = Node(number)

    return root

root = generate_nodes([1, 2, 43, 1, 56, 12, 5, 1, -2, 4333, 3])


- Practitioner December 11, 2018 | Flag Reply

Add a Comment

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.


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


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