• + 1 comment

    Your code will give wrong answer for the sequence 1,1,1,2,2,2,3,4,5,5,5,5,6,7. Because 'pos' will written the position of 5. Final sequence will be either 4,5,5,5,5 or 5,5,5,5,6 according to your code as frequency of 5 is maximum whereas 1,1,1,2,2,2 is the actual answer