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.
Weighted Uniform Strings
Weighted Uniform Strings
Sort by
recency
|
799 Discussions
|
Please Login in order to post a comment
Here is a solution in python with O(n + m) time and O(m) space.
The space is in part because althogh the set cat grow as large as 26, values can be access at O(1) and the queries are the values that we search for in the set at a time of O(m) and equel space.
Here is problem solution in python java c++ c and javascript - https://programmingoneonone.com/hackerrank-weighted-uniform-strings-problem-solution.html
Python Tip rather than a solution: - A data type 'set' is faster to find a value than a data type 'list'. - It is because 'set' follows hash-based search O(1) and 'list' follows the linear search O(n).
My C++ Solution: