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.
But im still not gettin your second point "Secondly, another problem with this code is when the second string is iterating through the map. It is possible that you delete a previous entry that you have already done."
Because during second loop while adding entry in map for character which already exist :
count.put(c, count.get(c)-1)
We are capturing previous value for that character[Key] and then subtracting it , So how we are getting affected even if it is creating new entry [Which hashmap is suppose to do if we try to add key which already exists].
Where im goin wrong .
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Strings: Making Anagrams
You are viewing a single comment's thread. Return to all comments →
Hello ACM , Thanks for explanation
But im still not gettin your second point "Secondly, another problem with this code is when the second string is iterating through the map. It is possible that you delete a previous entry that you have already done."
Because during second loop while adding entry in map for character which already exist :
count.put(c, count.get(c)-1)
We are capturing previous value for that character[Key] and then subtracting it , So how we are getting affected even if it is creating new entry [Which hashmap is suppose to do if we try to add key which already exists].
Where im goin wrong .