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.
A good solution. A bit of optimisation to your code is to iterate through the list once and store the characters as keys opposed to their count as values in a dict(). This avoids the list.count going O(n) for each character and hence avoids O(n^2) solution.
Food for thought.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Happy Ladybugs
You are viewing a single comment's thread. Return to all comments →
A good solution. A bit of optimisation to your code is to iterate through the list once and store the characters as keys opposed to their count as values in a dict(). This avoids the list.count going O(n) for each character and hence avoids O(n^2) solution. Food for thought.