Skip to content

Instantly share code, notes, and snippets.

View aishraj's full-sized avatar

Aish aishraj

View GitHub Profile
@aishraj
aishraj / Hint.md
Created November 13, 2011 09:57 — forked from yuvipanda/Hint.md
2's Compliment Solution (InterviewStreet CodeSprint Fall 2011)

The number of 1's in the range 0..X (X is positive) is easy to calculate (Can you get a simple recurrence which does this in O(log X) ?) Another observation is that the number of 1's in -X is equal to the number of 0's in ~(-X) = X - 1. Using this, it is easy to calculate the answer for negative ranges as well.