For this problem, you are expected to pass a set of values user ids, x within a range, minX and minY inclusive through a series of n layers. If the final value is even, then that user is not a spammer otherwise, the user is a spammer. The output of your program should be the number of spammers and non-spammers.
This is how I approached the problem:
- The interval between successive outputs at the end of n layers is constant. (Please verify this yourself). With this fact, I pass the first two ids (minX and minX+1) through the n layers and save their outputs in variables say
firstandsecond. - I then find the difference between these two values and store them in a variable diff. i.e
diff = second - first - With this information, I then loop from minX to minY and at each stage, I check whether
firstis even or odd and keep track of that information and then increasefirstbydiff.
Below is my implementation in C++.
This isn’t the best solution you are going to get but it’s fast enough. Another editorial can be found on CodeChef, where this problem was taken from. Follow this link to view it: https://discuss.codechef.com/problems/SPAMCLAS
If you have an alternative solution, please feel free to share 👍


