Better method to solve specific algorithm.