Hello DIMAKATSO BOPAPE!

You’re almost there! The flaw in your solution is that you decided to use a List. The worst case time complexity of a checking if something exists in an Array or List (i.e. the contains method) is O(n). So effectively, you have a for loop which has time complexity of O(n) and then inside it you have another O(n) loop to check if sum — num exists in the List, thus the total time complexity of your solution is O(n²). I would suggest that you use a “Hash”ed data structure like a HashSet. That would decrease the total time complexity to O(n). Good luck! — If you need more information about time complexities in data structures in Java, here they are.

Talking about money, tech and how to make money from tech. Real estate investor. Full-stack engineer at https://www.hse24.de/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store