Explain logic and code

Problem linkCodeChef: Practical coding for everyone

right approach?

Problem description:
Geek Sundaram is a world renowned Master Chef. One of his signature dishes include Idly and Vada.

Each day he prepares M Idlies and N vadas and places them in a bucket. He asks his customers to pick two items from the bucket in whatever order they desire.

After picking two items, each customer is asked to place a vada back into the bucket if they had picked two similar items or else place an idly into the bucket.

At the end of the day, Geek is left with one item in the bucket. He is keen to find out what the last item could be since he doesn’t know the order in which the customers picked and replaced.

Help Geek find the last item.

Print one of the following as the output:

“IDLY” - if the last item is idly.
“VADA” - if the last item is vada.
“SAMBAR” - if the last item is unknown.

This question is certainly based on the observation. If you observe then you will find that final answer will not depend on “VADA”, it only depends upon “IDLY”. The reason is you can replace any two similar items with the “VADA” so when you got even number of “IDLY” then you are assure that after replacing all the items at any order you will always end up two similar number of items so the answer will be “VADA” but if you got odd number of “IDLY” then you will end up with two dissimilar number of items so answer will be “IDLY”.

If you still then i suggest you to first analyse this question by yourself!

For Code click here.