Added finding optimal solution for max