cancer16789
BAN USERIf two chords cannot share a point, then this problem is not at all interesting. Answer will always be 2 if 2n>=4
- cancer16789 May 19, 2012How did u get 2 for 4 points and 5 for 6 points?
if two chords can share a point the it will be 5 for 4 points and if they cannot, answer will always be two if 2n>=4
@Above , we don't need to actually remove the element from array. Just keep track of index on both sides, front and back.
- cancer16789 May 19, 20121 small correction
package binaryTreeQuestions;
import java.util.Stack;
public class TwoBSTPrinter {
private static Stack<BinaryTreeNode> stack=new Stack<BinaryTreeNode>();
public static void printSorted(BinaryTreeNode bst1,BinaryTreeNode bst2){
pushIntoStack(bst1);
printInorder(bst2);
while(!stack.isEmpty()){
System.out.println(stack.pop().data);
}
}
private static void printInorder(BinaryTreeNode bst){
if(bst==null){
return;
}
printInorder(bst.left);
while(!stack.isEmpty() && bst.data>stack.peek().data){
System.out.println(popFromStack());
}
System.out.println(bst.data);
printInorder(bst.right);
}
private static void pushIntoStack(BinaryTreeNode node){
if(node!=null){
stack.push(node);
pushIntoStack(node.left);
}
}
private static int popFromStack(){
BinaryTreeNode node=stack.pop();
pushIntoStack(node.right);
return node.data;
}
}
Can you elaborate more on this?
- cancer16789 May 20, 2012