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.
Instead of using an array of size 26, why not use a hashMap, which will have a size 26 in the worst case and in other cases, always less than that. This reduces space complexity and time pretty much remains O(n).
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Making Anagrams
You are viewing a single comment's thread. Return to all comments →
Instead of using an array of size 26, why not use a hashMap, which will have a size 26 in the worst case and in other cases, always less than that. This reduces space complexity and time pretty much remains O(n).