using System;
public class Program
{
public int totalLenght = 0;
public static void Main()
// here's a maze data, starting with a wall that has left and right walls connected to it
Wall maze = new(20) {
Left = new(23) {
Left = new(12) {
Left = new(15),
Right = new(3)
},
Right = new(45) {
Left = new(24) {
Left = new(4),
Right = new(7)
Right = new(32)
}
Right = new(24)
};
// compute the total length of the walls of the maze
// Expected output: 209
Console.WriteLine(GetLength(maze));
// computes the length of the provided wall + the length of its left and right siblings
public static int GetLength(Wall wall) {
// TODO
//if wall.left!=null
//GetLength(wall.left)
//totalLength += wall.Length'
if ( wall.Left != null){
GetLength(wall.Left);
totalLenght += wall.Length;
public class Wall {
public Wall Left;
public Wall Right;
public int Length;
public Wall(int length) { this.Length = length; }