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.
2's complement
2's complement
Sort by
recency
|
40 Discussions
|
Please Login in order to post a comment
Honestly, some puzzles just aren't worth the time / points. This one looks like it's just bookkeeping.
Running the range and doing pop-counts takes too long. Instead, given the range, determine how often each of the 32-bits possible will be a 1. The range may contain some number of full cycles, with half 1s and half 0s, and then some off-cycle handling on either end. Might have to handle a case for the positive portion of the range and a case for the negatives -- TBD.
Here is 2"s complement problem solution in Python Java C++ and c programming- https://programs.programmingoneonone.com/2021/07/hackerrank-2s-complement-problem-solution.html
Python3 solution
https://www.youtube.com/watch?v=4qH4unVtJkE If someone is interested
Can't figure out why it is not working