Manasa And Stones

 

After spending about 1 hour tinkering with this problem, thinking about permutations and combinations and also trying different approaches on that, I realized that there was some pattern in the sum of the values which were being obtained, it is often the case in many medium or easy level problems which look quite overwhelming in the starting and would feel that this would take a lifetime to understand often have some hidden pattern which is the main idea of the whole problem.

It's around 11:25 p.m., with Charlie's Losing My Mind being played on Spotify, am trying not to lose mine, and get with more stuff done, after this one liner problem statement, it's disgustingly awkward how Python simplifies the whole problem, switching from cpp, this is no less than a miracle of doing so many things in just one line, I think that even if cpp may have functions like those for sorting and all but the whole syntax and it's rules are far different than Python, in cpp you can be very naive and just throw a tedious algo to the problem without much thought but in Python you need to come up with a bettter approach if you don't want to have a meeting with the TLC.

Off for another problem, maybe some duo after that, it's been quite dubious everywhere.

Here's the solution to the problem statement, let's see if you can understand the one liner return statement...

def stones(n,a,b):
    return sorted(list(set([a*i+b*(n-1-i) for i in range(n)])))

Comments

Popular Posts