Yes. Lists, as the error states, are unhashable (because they can be mutated and thus their hash would change and that is bad). lru_cache's docs state:
Since a dictionary is used to cache results, the positional and keyword arguments to the function must be hashable.
Nice approach and clean. :)
Cheeky
This comment is hidden because it contains spoiler information about the solution
I have the same solution, but I kind of guessed it would work and have no idea why.
Could anyone explain the maths behind this solution? (If you do, please don't forget the spoiler flag)
too slow
The description states that the condition for performing changes to the array is
for any i, j pair.
12 > 12
is false, so no changes are made to the array, which is then summed: 12 + 12 = 24 as expected.That is just an artifact of how the test results are printed, it's not an error in your solution.
Yes. Lists, as the error states, are unhashable (because they can be mutated and thus their hash would change and that is bad).
lru_cache
's docs state:yeah same here
why I cant find fractions module when using pycharm
Excellent and concise solution!
I did the same thing and it timed out.