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.
That's the most efficient way to solve it using bit manipulation because low-level techniques are usually fast.
If you really care about speed then consider using int as the data holder and use bitwise operation to perform things.
But if you want to write code that are easier to read that mimic bitwise then use bitset because there are built-in functions and overloaded operators for it.
bitset<26> gem, elems;
gem.set();
for each c in string {elems.set(c-'a')}
gem &= elems;
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 →
That's the most efficient way to solve it using bit manipulation because low-level techniques are usually fast. If you really care about speed then consider using int as the data holder and use bitwise operation to perform things. But if you want to write code that are easier to read that mimic bitwise then use bitset because there are built-in functions and overloaded operators for it.
bitset<26> gem, elems;
gem.set();
for each c in string {elems.set(c-'a')}
gem &= elems;