Solutions for challenge 3


after I did my solution def find_sum(lst, k): resp = [] for i in range(len(lst)): temp = k - lst[i] if temp in lst: resp = [lst[i], lst[lst.index(temp)]] break return resp
and checked the solutions proposed I’m interested in knowing how my approach performs in comparison with the solutions proposed.

Course: Educative: Interactive Courses for Software Developers
Lesson: Educative: Interactive Courses for Software Developers

Hello @jobhiuserkanaam
Thank you for reaching out to us. We really appreciate learners who think outside of the box and come up with alternate solutions. While the working and output of your code is absolutely correct, it has a higher time complexity. Time complexity of your code is: O(n^3) = [O(n) =>list.index * O(n) => for loop * O(n) =>in operator]. On the other hand, the time complexity of the code provided on the platform is: O(n(log(n)) =[O(n(log(n)=> list.sort() + O(n)=> while loop].I hope this helps!

1 Like