<repo_name>JaiberS/holbertonschool-interview<file_sep>/0x01-insert_in_sorted_linked_list/0-insert_number.c
#include "lists.h"

/**
 * insert_node - adds a new node at a listint_t list.
 * @n: new data
 * @head: first node
 *
 * Return: the address of the new element, or NULL if it failed
 */

listint_t *insert_node(listint_t **head, int n)
{
	listint_t *new, *head2, *ant;
	unsigned int i = 0;

	if (head == NULL) {
		return (0);
    }
	new = malloc(sizeof(listint_t));
	if (new == NULL)
	{
		free(new);
		return (NULL);
	}
	if (*head == NULL)
	{
		new->n = n;
		new->next = NULL;
		*head = new;
		return (new);
	}
	head2 = *head;
    ant = NULL;
	for (;head2 != NULL && head2->n < n; ant = head2, head2 = head2->next, i++)
    ;
	new->n = n;
	if (ant != NULL)
	{
		ant->next = new;
		new->next = head2;
	}
	else
	{
		new->next = *head;
		*head = new;
	}
	return (new);
}<file_sep>/0x02-heap_insert/1-heap_insert.c
#include "binary_trees.h"

/**
 * heap_insert - Write a function that inserts a value into a Max Binary Heap
 * @root: is a double pointer to the root node of the Heap
 * @value: is the value store in the node to be inserted
 *
 * Return: pointer to the inserted node, or NULL on failure
 */

heap_t *heap_insert(heap_t **root, int value)
{
    heap_t *new, *head;
 	int max_level = 0;

	if (*root == NULL) {
		new = malloc(sizeof(heap_t));
		if (new == NULL) {
			return (NULL);
		}
		new->right = NULL;
		new->left = NULL;
		new->n = value;
		new->parent = NULL;
		*root = new;
		return (*root);
	}
	head = *root;

	while (head->right != NULL) {
		head = head->right;
		max_level++;
	}
	head = *root;

	new = heap_insert_with_levels(root, value, 0, max_level + 1);

	return (new);
}


/**
 * heap_insert_with_levels - Write a function that inserts a value into a Max Binary Heap
 * @root: is a double pointer to the root node of the Heap
 * @value: is the value store in the node to be inserted
 *
 * Return: pointer to the inserted node, or NULL on failure
 */

heap_t *heap_insert_with_levels(heap_t **root, int value, int level, int max_level)
{
    heap_t *new, *head;

	head = *root;
	if (level == max_level) {
		while(head->parent != NULL) {
			head = head->parent;
		}
		new = heap_insert_with_levels(&head->right, value, level + 1, max_level);
		return (new);
	}
	if (head->left == NULL) {
		new = malloc(sizeof(heap_t));
		if (new == NULL) {
			return (NULL);
		}
		new->right = NULL;
		new->left = NULL;
		new->n = value;
		head->left = new;
		new->parent = head;
		while (head != NULL && new->n > head->n) {
			value = head->n;
			head->n = new->n;
			new->n = value;
			new = head;
			head = head->parent;
		}
	} else if (head->right == NULL) {
		new = malloc(sizeof(heap_t));
		if (new == NULL) {
			return (NULL);
		}
		new->right = NULL;
		new->left = NULL;
		new->n = value;
		head->right = new;
		new->parent = head;
		while (head != NULL && new->n > head->n) {
			value = head->n;
			head->n = new->n;
			new->n = value;
			new = head;
			head = head->parent;
		}
	} else {
		new = heap_insert_with_levels(&head->left, value, level + 1, max_level);
	}
	return (new);
}
<file_sep>/0x02-heap_insert/README.md
# holbertonschool-interview
Data structures

Please use the following data structures and types for binary trees. Don’t forget to include them in your header file.<file_sep>/0x00-lockboxes/0-lockboxes.py
#!/usr/bin/python3


def canUnlockAll(boxes):
    if not isinstance(boxes, list) or len(boxes) == 0:
        return False
    for box in boxes:
        if not isinstance(box, list):
            return False
    if len(boxes) == 1:
        return True
    keys = [0]
    for j in keys:
        for i in boxes[j]:
            if 0 < i < len(boxes) and i not in keys:
                keys.append(i)
            if len(keys) == len(boxes):
                return True
    return False
