The general pattern that I followed was, remove the Arithmetic mean for every pair of numbers in the given sequence, and then the ones that would be left would not be in AP when the process finished. I tested it for small input sizes, and it seemed to work.
Any feedback would be greatly appreciated and since I am very new,please forgive any naive mistakes I might have done.
(PS- I think my input method is pretty stupid , would highly appreciate if someone could show how to handle very large datasets)
@mightymosquito :, i followed a slightly different procedure.
maintain an array ans[] which will finally contain the list of numbers to be displayed.
add the first and the second element i.e B[0] and B1 to the array ans[].
now, for every element B[i],(i>=2):
consider pairs of B[i] and ans[j](j >= 0):
if arithmetic mean of B[i] and ans[j] is present ,dont add B[i] to ans[].
also, maintain a kind of hashmap to find which elements are already present in the ans[].
This solution fetched me 0.691 pts.here’s my solution
@mightymosquitoReason that you got TLE is your algorithm complexity is not good enough to get AC within TL.
As you mentioned in the question that you are removing arithmetic mean for every pair of numbers. That is every time you are selecting 2 numbers out of M, C(M,2), which is equal to
C(M,2) = (M * (M - 1)) / 2
So your algorithm have time complexity order of M^2, now with M = 100000 you will certainly get TLE.
You need a better algorithm. I suggest you read editorial for the same problem admins posts it.
EDIT:
Follow this question for algorithms to solve this problem.
And as far knowing when do you need new algorithm to solve a particular problem is concerned, I suggest practice as many as problems you can, then you will know which complexity algorithm would pass given question just by reading the question.
I tried making this algorithm faster,but was unable to do so.Can it be made faster and if yes ,then what should be my approach, moreover when should I start thinking about a new algorithm when such problems arise when solving problems??-thanks
@mightymosquito Even i had a sort of exhaustive checking algorithm that wasnt very efficient so i put a condition that if number of input elements is greater than around 40,000, then i process upto there only and neglect other numbers. By processing only a maximum of 40k inputs.
in short: