# Microsoft Technical Interview November 2010

Hi guys , these questions I received from Microsoft Ireland for a position with Windows Azure team

They are really so organized , to be honest I applied by mistake to Ireland (I am in USA) ,

so I said they will not proceed so hay they really proceed and asked me to take this Technical Test ,

it is 2 hours Test you will receive it on your email once you follow their instructions.

So I want to share with you the questions and the answers that I came up with , really it was a lot of fun.

Question 1:

Link nodes at same level in a binary tree

void linkSameLevel(struct node *t);

public void linkSameLevel(Node t); so here is what I came up with I used a recursive technique:

`using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace linkSameLevel{    public class Node    {        public int value;        public Node left;        public Node right;        public Node level;    }    class Program    {        static void Main(string[] args)        {            Node one = new Node();            one.left = null; one.right = null;             one.level = null; one.value = 1;            Node three = new Node();            three.left = null; three.right = null;             three.level = null; three.value = 3;            Node five = new Node();            five.left = null; five.right = null;             five.level = null; five.value = 5;            Node seven = new Node();            seven.left = null; seven.right = null;             seven.level = null; seven.value =7;            Node two = new Node();            two.left = one; two.right = three;             two.level = null; two.value = 2;            Node six = new Node();            six.left = five; six.right = seven;             six.level = null; six.value = 6;            Node four = new Node();            four.left = two; four.right = six;             four.level = null; four.value = 1;            linkSameLevel(four);            StringBuilder sb = new StringBuilder();            Node current = one;                        sb.Append(current.value.ToString()+"->");            while (current.level!=null)            {                sb.Append(current.level.value.ToString()+"->");                current = current.level;            }            Console.WriteLine(sb.ToString());            Console.Read();        }        public static void linkSameLevel(Node n)        {            if (n == null) return;            if (n.level != null)                if(n.level.left!=null)                   n.right.level = n.level.left;                        if(n.right!=null)                n.left.level = n.right;            linkSameLevel(n.left);            linkSameLevel(n.right);        }    }}`

Question 2:

Matching braces

int checkBraces(char* s);

public bool checkBraces(string s); so this was so easy :

`using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace checkBraces{    class Program    {        static void Main(string[] args)        {            Console.WriteLine(checkBraces("{(3+5)-[2*1]{}([])}"));            Console.WriteLine(checkBraces("{(3+5)-[2*1){}([])}"));            Console.WriteLine(checkBraces(""));            Console.Read();        }        public static bool checkBraces(string s)        {            //test            if (s.ToCharArray().Length <= 0) return false;            bool resul = true;            // O(1) search            Dictionary<char, char> openBracces = new Dictionary<char, char>()            {                {'{','}'},                {'[',']'},                {'(',')'},            };            Dictionary<char, char> closedBracces = new Dictionary<char, char>()            {                {'}','{'},                {']','['},                {')','('}            };            Stack<char> token = new Stack<char>();            char[] equation = s.ToCharArray();            foreach (char item in equation)            {                if (openBracces.ContainsKey(item))                    token.Push(item);                if (closedBracces.ContainsKey(item))                    if (token.Pop() != closedBracces[item])                        return false;            }           return resul;        }    }}`

so I hope this will help some one on the road .

## 22 Comments

Comments have been disabled for this content.