Stacks: BalancedExpressions

In the final solution there is a an assumption that 2 arrays should contain brackets in the given order. This isn’t maintainable. If someone changes order (which is not wrong) the code will break. Using a Map will be better

Not sure I understood your criticism. The code looked fine to me. I probably would have used an enum for the bracket types, but I am pretty confident Mosh’s code worked.

My enum would have looked like this:

enum Bracket {
  ANGLE('<', '>'),
  SQUARE('[', ']'),
  PARENTHESES('(', ')'),
  CURLY('{', '}');

  private final char open;
  private final char close;

  Bracket(char open, char close) { ... }

  private static final Map<Character, Bracket>
    BY_TYPE = byType();

  public static boolean isBracket(char c) {
    return BY_TYPE.containsKey(c);
  }

  public static Bracket for(char c) {
    checkArgument(isBracket());
    return BY_TYPE.get(c);
  }

  private static Map<Character, Bracket> byType() {...}
}

Then we can use those methods to add the brackets to the stack and pop them off when appropriate and check if they are the right type. Finally returning true if the stack was empty at the end.