Rocco
BAN USERUse MVC where
public class Controller { //User updates will make a call to this class
statusUpdate(String userId, Status status); //makes call to model
postPhoto(String userId, Photo photo);
}
public class Model { //Does db updates and notifies view
statusUpdate(String userId, Status status); //Updates status in DB, finds user and his friends, notifies friends views with new status
postPhoto(String userId, Photo photo);
}
public class View {
String userId;
Wall wall;
updateWall(User user, Status status);
updateWall(User user, Photo photo);
}
val corresponf to root = -INT_MAX
val for left most tree is 0
val for right most part is -1
for other nodes val is some negative number
for leaf node the value val is not checked before printing
for other node this val value is chked before printing
antiprint(root,val=-INT_MAX){
if(root->left){
if(val==-INTMAX || val==0 ) { //left most part of tree
print root->data;
antiprint(root->left,0);
}
elseif(val<0)//right child of left most part
antiprint(root->left,val-1);
}
elseif(!root->right) print root->data; //leaf
else { //right
if(val==-1 || val==-INT_MAX) {//right most part of tree
antiprint(root->right,-1);
print root->data;
}
elseif(val==0)
antiprint(root->right,-2);
elseif(val<0)
antiprint(root->right,val-1);
}
}
A solution no better than above :
1) Make a binary tree(same structure) out of the given LL.(Structure has two child pointer)
2) For node with data find it in tree.lets sa its 'n' the child greater than n is min(n->right).
Complexity O(nlogn) + O(nlogn) = O(nlogn) for optimum BST
Space O(n)
hope this will work in O(n)..please correct me if i am wrong
bool pattern[3][8] ; //constant memory
pattern[1]= [0,1,1,1,0,1,0,1] ; // for integer 1-8,25-32,..
pattern[2]= [1,1,0,1,0,1,1,1] ; //for int 9-16,33-40,..
pattern[3]= [0,1,0,1,1,1,0,1] ; //for int 17-24,41-48,..
//if pattern[i][j] =1 means its a factor of 2 or 3 or both.
no=0;
while(1){
for int j=1,3{
for int i =1,8{
if pattern[j][i]==1 print no+i;
}
no+=8;
}
}
}
pseudo code:
findrange(bst,min,max){
if (bst==null) return ;
if(min<= bst->data <= max) {
findrange(bst->left,min,max);
print bst->data;
findrange(bst->right,min,max);
}
elseif (bst->data <min)
findrange(bst->right,min,max);
elseif (bst->data <max)
findrange(bst->left,min,max);
else
return;
}
- Rocco December 16, 2013