We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The problem with this implementarion is the complexity. You are doing it in O(n²), while you can do this in O(n). Even sorting the list have a better complexity O(n*log(n)).
An example of a patological case is the list [5, 5, 5, 5, 5 ,6] or something like that.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Find the Runner-Up Score!
You are viewing a single comment's thread. Return to all comments →
The problem with this implementarion is the complexity. You are doing it in O(n²), while you can do this in O(n). Even sorting the list have a better complexity O(n*log(n)). An example of a patological case is the list [5, 5, 5, 5, 5 ,6] or something like that.