Solution for thirdgreatest problem