# CAPPLE -- Getting Wrong Answer

I tried to solve this using list . What is wrong in it ? When I tried with set , it worked fine.Please help.
The link to question : http://www.codechef.com/problems/CAPPLE
The link to my solution http://www.codechef.com/viewsolution/5976138

Thanks

You are mistaken in the unique function. Read this :

Notice that an element is only removed from the list container if it compares equal to the element immediately preceding it. Thus, this function is especially useful for sorted lists.

Thus when input is something like this:

``````6
1 2 2 3 3 2
``````

Your code gives 4 as the answer, while the answer is 3 because your list becomes 1 2 3 2 while you intended 1 2 3.

Hope it clearsâ€¦

You are using the unique() function of list.

As per http://www.cplusplus.com/reference/list/list/unique/ ->
Notice that an element is only removed from the list container if it compares equal to the element immediately preceding it. Thus, this function is especially useful for sorted lists.

This means that for a test case such as

4

1 2 3 3

Your result will be correct, ie. 3

But for

4

3 1 2 3

Your result will be incorrect, ie. 4

Use some other method to remove repetitions or sort the list before using unique.