is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.
Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.
Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.
for each bit, divide the number into 3 parts: high now low
- zhao April 19, 2012for example: 110110, if we are processing the third bit, 110->high,1->now,10->low, (i=2)
Let's see how many ways we can make the bit now to "1"
If now is 1, when the higher part is less than high, the lower part can be 00...0--11...1, so that is high*(1<<i).. when the higher part is high, the lower part can be 000--low, so that is low+1;
If now is 0, the higher part can only be less than high, so that is high*(1<<i)
int count(int n)
{
int a[40],len=0,tmp=n;
while(n)
{
a[len++]=n&1;
n>>=1;
}
int low=0,high=tmp>>1,ans=0;
for(int i=0;i<len;i++)
{
ans+=high*(1<<i);
if(a[i]==1)
{
ans+=low+1;
low+=(1<<i);
}
high>>=1;
}
return ans;
}