Rayden
BAN USERYou didnt handle the case if key is equal to lowest OR key is equal to highest. This should come after the AND you are doing and if it is true you MUST return P.
One more thing for this code to work you MUST first traverse the whole BST and make sure that the input given does exist in the tree. Of course you can also ask your interviewer if the input is guaranteed to be in the tree.
Whenever you encounter a black you will check its 8 neighbors to see if they are also black. You will do the same thing for the black neighbors again and again until there is no neighbor remains.
Assuming you can destroy the original matrix just change the black neighbors to white as you encounter them.
You can assign the control for 8 neighbors to seperate cores to speed things up.
void fib(int start, int length)
{
if (start<0)
{
cout<<"invalid start"<<endl;
return;
}
else if(length<=0)
{
cout<<"invalid length"<<endl;
return;
}
if ( (start==0) && (length>0) )
{
cout<<"0 ";
length--;
if(!length)
{
cout<<endl;
return;
}
}
int a = 0;
int b = 1;
int current = 1;
while(current<start)
{
int c = a + b;
a = b;
b = c;
current++;
}
while(length)
{
int c = a + b;
a = b;
b = c;
cout<<c<<" ";
length--;
}
cout<<endl;
}
Now first of all you must note something even though it says 10billion you can have only 4billion distinct integers (2^32). S if we had 500MBmemory we could have mapped each of these integers to a bit vector.
Since we have less memory vijay's solution should be used.
As a last note this is actually a question from the book and both of these solutions are discussed in depth.
Now first of all you must note something even though it says 10billion you can have only 4billion distinct integers (2^32). S if we had 500MBmemory we could have mapped each of these integers to a bit vector.
Since we have less memory vijay's solution should be used.
As a last note this is actually a question from the book and both of these solutions are discussed in depth.
Now first of all you must note something even though it says 10billion you can have only 4billion distinct integers (2^32). S if we had 500MBmemory we could have mapped each of these integers to a bit vector.
Since we have less memory vijay's solution should be used.
As a last note this is actually a question from the book and both of these solutions are discussed in depth.
where is the overflow detection.
- Rayden March 05, 2012