using System.Collections.Generic;
public static void Main()
Console.WriteLine("Hello World");
public static int Task1(Node node)
if (node.Left == null && node.Left == null)
if (node.Left == null || node.Right == null)
var h1 = Task1(node.Right);
var h2 = Task1(node.Left);
if (h2 == -1 || Math.Abs(h1 - h2) > 1)
public static bool Task2(Node node1, Node node2)
var queue = new Queue<Node>();
var node = queue.Dequeue();
foreach(var child in node.Adjacent)
public static Node Task3(int[] array, int start, int end)
return new Node() { Data = array[start] };
var middle = (start + end)/2;
node.Left = Task3(array, start, Math.Max(middle, middle - 1));
node.Right = Task3(array, Math.Min(middle + 1, end), end);
node.Data = array[middle];
public List<Node> Task4(Node root)
var result = Task4_Helper(new List<Node> { root });
public List<Node> Task4_Helper(List<Node> level)
var newLevel = new List<Node>();
foreach(var node in level)
newLevel.Add(node.Right);
var result = Task4_Helper(newLevel);
result.Add(level.First());
public bool Task5(Node root)
return Task5_Helper(root, int.MinValue, int.MaxValue);
public bool Task5_Helper(Node node, int min, int max)
if (node.Data > max || node.Data <= min)
if (!Task5_Helper(node.Left, min, node.Data))
if (!Task5_Helper(node.Right, node.Data, max))
public Node Task6(Node node)
Node helper = node.Right;
while(helper.Left != null)
while(node.Parent != null && node.Parent.Left != node)
public List<Node> Adjacent { get; set; }
public Node Left { get; set; }
public Node Right { get; set; }
public bool IsVisited { get; set; }
public int Data { get; set; }
public Node Next { get; set; }
public Node Parent { get; set; }