Jan-09-2021, 07:27 AM
I don't know what the task is, but a few things:
1. What's the worst case complexity for
2. Remember that searching a list is linear, so doing that on each iteration of the loop (line 7) will be expensive as n grows. Does
1. What's the worst case complexity for
len(A)
? If it's expensive, do you need to do it 3 times?2. Remember that searching a list is linear, so doing that on each iteration of the loop (line 7) will be expensive as n grows. Does
river
need to be a list? If so, you might additionally want to keep the items in a set that you just use for keeping track of which items you've seen, since lookup in a set is done in constant time.