fix for case 1 2 2 and 1 3 4 3 2 1