Problem solving in optimized way