Question: this is currently O(n^2) make it O(n) import sys sys.setrecursionlimit(100000) def dumbo_func(data, start_index = 0): Takes a list of numbers and does weird stuff with
this is currently O(n^2) make it O(n)
import sys sys.setrecursionlimit(100000)
def dumbo_func(data, start_index = 0): """Takes a list of numbers and does weird stuff with it""" if len(data) == 0: return start_index else: if (data[0] // 100) % 3 != 0: return dumbo_func(data[1:], start_index +1) else: return dumbo_func(data[1:], start_index)
print(dumbo_func(list(range(10000))))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
