You are viewing a single comment's thread. Return to all comments →
Check for duplicates helps to avoid unnecessary computations.
if len(arr) != len(list(set(arr))):
result = 0
This is relevant for one of the tests.
to avoid even more unnecessary computations:
len(list(set(arr))) -> len(set(arr))
You can also abort when diff is zero to pass the test.
Not sure how relevant, this passes all tests:
diffs = 
for i in range(len(arr)-1):