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.
You're using a list as the data structure to store the values present in the string (solvec), and then iterating over it repeatedly in the second for loop. This makes the run time O(n**2).
I'd recommend reviewing the differences between sets and lists, and maybe implementing a set yourself to really understand it. The goal is to understand why each of these operations are the given complexity.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Weighted Uniform Strings
You are viewing a single comment's thread. Return to all comments →
You're using a list as the data structure to store the values present in the string (
solvec
), and then iterating over it repeatedly in the second for loop. This makes the run time O(n**2).I'd recommend reviewing the differences between sets and lists, and maybe implementing a set yourself to really understand it. The goal is to understand why each of these operations are the given complexity.