Algorithm based problem solve code