I am getting a time limit exceeding error.Could someone tell me how to correct it? Thanks in advance.

Here is the link to my code : http://ideone.com/bXRMve

I haven’t read the question statement. But i just had a look into your solution.

One obvious reason why your pgm gives TLE is because you have two “infinite-loops” in your pgm.

```
while(a[k]==a[n-1])
j++;
```

If a[k] happens to be equal to a[n-1], then the condition will always be true, and the pgm will never break out of this. There are two such instances in your code. Please try after rectifying them.

Regards.