sahilsingla112
BAN USER- 0of 0 votes
AnswersDesign an OO parking lot.
- sahilsingla112 in India
What classes and functions will it have. It should say, full, empty and also be able to find spot for Valet parking.
The lot has 3 different types of parking: regular, handicapped and compact.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer
private static <T> DoublyLinkedList<T> flatten(BinaryTreeNode<T> btn) {
DoublyLinkedList<T> dll = new DoublyLinkedList<T>();
if(btn != null) {
dll.append(flatten(btn.getLeftChild()));
dll.add(btn.getValue());
dll.append(flatten(btn.getRightChild()));
}
return dll;
}
Is this solution correct?? what about the "tree can be modified" clause
...
its not recursive
- sahilsingla112 August 09, 2012@jiangok, u seem correct but how about the second part "the tree can be modified" ?
- sahilsingla112 August 09, 2012One pass means we can traverse the list only once.
- sahilsingla112 August 08, 20121) Take two pointers both at the start of linklist.
2) Advance one pointer by 5 positions.
3) then advance both the pointers simultaneously until second pointer becomes null.
4) Return first pointer.
node* fun(node* head)
{
if(head==null)
{cout<<"not enough elements"; return null;}
node*ptr1,*ptr2=head;
for (int i=0;i<5&&ptr2!=null;i++)
ptr2=ptr2->next;
if(ptr2==null) {cout<<not enough elements; return null;}
while (ptr2!=null)
{
ptr1=ptr1->next;
ptr2=ptr2->next;
}
return ptr1;
}
Example: A->B->C->D->E->F->G->*(end)
5th from last: C
after loop1
ptr2=F
after loop2
ptr1=c
can you check my last post please and tell me if it is correct
- sahilsingla112 August 09, 2012