Let's look at the code first - List<string> list = new List<string> { "({[]})", "][(]}})(" }; - Poor choice of variable name. You picked `expression` just a little below, that is a good one. Why not use the plural form of it: `expressions`? foreach (var barcketsList in list) - `barcketsList` contains a typo, not a big deal usually. However, you should pay some more attention for an interview. - `bracket-s` + `List` you really don't want hinting this is an array/collection/list twice. foreach (var barcketsList in list) // <- unnecessary white line { - Don't leave white line just anywhere within a method in your code. They should be used to divide the logical blocks, eg: declaration/initialization vs logic vs return, logic#1 vs logic#2 string expression = barcketsList; Stack<char> stack = new Stack<char>(); char[] symbols = expression.ToCharArray(); - A temporary variable `expression` is not necessary here. In fact, both this and `barcketsList` is only used once. You can substitute one by the other. - Use `var` when you can, it makes the variable names aligned thus making scanning easier. The variable name itself or its right-hand side assignment should give enough clue usually, plus you can always mouse-over with intellisense. <!-- fix: code block --> for (int start = 0; start < symbols.Count(); start++) { char temp = symbols[start]; - Since you are just using the index (`start`) to get the char, you can use a `foreach`-loop here <!-- fix: code block --> if (stack.Count == 0) //only closer no opening { Console.WriteLine("NO"); flagPrint = true; break; - The use of `flagPrint` here to escape the default final output is a bit more of a hack. For instance, since you are using `stack.Any()` to check for balance, you can push the closing bracket and `break` out of the loop to achieve the same behavior. You can also take an another approach and extract a `IsBalanced` out of existing code and use `return`. <!-- fix: code block --> if (!stack.Any() && !flagPrint) { Console.WriteLine("YES"); } else if (!flagPrint) { Console.WriteLine("NO"); } - If we were to keep the flag, this part can be reduced to: if (!flagPrint) { Console.WriteLine(!stack.Any() ? "YES" : "NO"); } What is not in the code --- - `IsBalanced` is not in a separated method. - Lack of argument checking/error handling Solution --- public void CheckAllExpressionsAreBalanced() { var expressions = new List<string> { "({[]})", "][(]}})(" }; foreach (var expression in expressions) { //Console.WriteLine("Expression `{0}` {1} balanced.", // expression, // IsBalanced(expression) ? "is" : "is not"); Console.WriteLine(IsBalanced(expression) ? "YES" : "NO"); } } // Define other methods and classes here public bool IsBalanced(string expression) { // definition var brackets = new[] { "()", "{}", "[]" }; var pairedBrackets = brackets.ToDictionary(x => x[0], x => x[1]); // validation var invalidCharacters = expression.ToCharArray() .Distinct() .Where(c => !pairedBrackets.ContainsKey(c) && !pairedBrackets.ContainsValue(c)); if (invalidCharacters.Any()) throw new ArgumentException("`expression` contains invalid characters: " + string.Join(", ", invalidCharacters)); // implementation var stack = new Stack<char>(); foreach (var c in expression) { var isOpening = pairedBrackets.ContainsKey(c); var pair = isOpening ? pairedBrackets[c] : pairedBrackets.First(x => x.Value == c).Key; if (isOpening) { stack.Push(c); } else { // closing bracket with empty stack if (!stack.Any()) return false; // closing bracket doesnt match last opening bracket if (stack.Peek() != pair) return false; // matched stack.Pop(); } } return true; } EDIT: I skipped the requirements...