Jan-09-2021, 06:49 AM
Heya, I've been running through Codility challenges and came upon a snag.
This program is meant to output the shortest time (K) possible to cross the river (every integer between 0 and X + 1 is covered by a leaf); it runs at 100% correctness but fails on all performance tests.
I'm at a loss as to how to increase the speed here:
Thanks for any tips! (:
This program is meant to output the shortest time (K) possible to cross the river (every integer between 0 and X + 1 is covered by a leaf); it runs at 100% correctness but fails on all performance tests.
I'm at a loss as to how to increase the speed here:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
def solution(X, A) : K = 0 river = list () #UNUSABLE-LEAVES-BE-GONE for leaf in range ( len (A)) : #DUPES-BE-GONE if A[K] in river: K = K + 1 continue #BUILD A BRIDGE else : river.append(A[K]) #BRIDGE IS DONE if len (river) = = X : break #HERE BE AN ITERATION INCREMENT K = K + 1 #BRIDGE WAS SUCCESSFUL if K < len (A) : print ( 'tick' ,K, 'out of:' , len (A) - 1 ) #BRIDGE WAS A FLOP else : print ( - 1 ) pass |