An Efficient Approach to Solve Mastermind Optimally