Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Codility Frog River One
#1
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:
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
Thanks for any tips! (:
Reply


Messages In This Thread
Codility Frog River One - by Westerner - Jan-09-2021, 06:49 AM
RE: Codility Frog River One - by ndc85430 - Jan-09-2021, 07:27 AM
RE: Codility Frog River One - by deanhystad - Jan-09-2021, 06:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Frog Puzzle Random To Custom MoreMoney 4 544 Mar-26-2024, 08:38 AM
Last Post: MoreMoney
  Codility Binary Gap Exercise Westerner 2 1,847 Jan-08-2021, 09:20 PM
Last Post: Westerner

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020