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.
I like this.
People have already explained how duplicates are avoided.
I particularly like the other feature (because I had to think about it to understand it),
if(letter[c-'a']==r){
means if up until now we have found this element in as many rocks as we have examined before this rock, it's still a gem-element, so it remains one after this rock as well.
But I don't like having
if(letter[c-'a']==rocks){count++;}
inside every every rock since it can only be true when r == rocks-1. I'd prefer to keep s[] outside the outer loop, and after all the rocks have been parsed, go through all the elements in the last rock again, counting if they have been found exactly rock times (and incrementing their count, so they aren't double-counted for duplicate elements in the last rock.)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Gemstones
You are viewing a single comment's thread. Return to all comments →
I like this. People have already explained how duplicates are avoided. I particularly like the other feature (because I had to think about it to understand it),
means if up until now we have found this element in as many rocks as we have examined before this rock, it's still a gem-element, so it remains one after this rock as well.
But I don't like having
inside every every rock since it can only be true when r == rocks-1. I'd prefer to keep s[] outside the outer loop, and after all the rocks have been parsed, go through all the elements in the last rock again, counting if they have been found exactly rock times (and incrementing their count, so they aren't double-counted for duplicate elements in the last rock.)