Solve permutation successor and evaluate expressions | Meta Interview Question