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.
c++ solution. The key is that NOT operation on bits does the 'flipping'. And since we operate on unsigned positive ints, gotta add 2 times INTMAX+1 to avoid negative numbers.
longflippingBits(longn){return~n+2l*INT32_MAX+2;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Flipping bits
You are viewing a single comment's thread. Return to all comments →
c++ solution. The key is that NOT operation on bits does the 'flipping'. And since we operate on unsigned positive ints, gotta add 2 times INTMAX+1 to avoid negative numbers.