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:
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:
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)
passThanks for any tips! (:
