You have given 2 array. You need to find whether they will
create the same BST or not.
For example:
Array1:10 5 20 15 30
Array2:10 20 15 30 5
Result: True
Array1:10 5 20 15 30
Array2:10 15 20 30 5
Result: False
One Approach is Pretty Clear by creating BST O(nlogn) then
checking two tree for identical O(N) overall O(nlogn) ..we
need there exist O(N) Time & O(1) Space also without extra
space .Algorithm ??
DevoCoder
guest
Posted 3 months ago #
#define true 1
#define false 0
int check(int a1[],int a2[],int n1,int n2)
{
int i;
//n1 size of array a1[] and n2 size of a2[]
if(n1!=n2) return false;
//n1 and n2 must be same
for(i=0;i<n1-1;i++)
{
if( !( (a1[i]>a1[i+1]) && (a2[i]>a2[i+1]) )
) return false;
}
return true;//assumed that each array doesn't contain
duplicate elements in themshelves
}
print ur name without using any semicolon in c/c++....
21 Answers Bosch, TCS, Wipro,
Why do we need volatile in c?
being a chemical engineer and with an aggregate of 80% why you opt for TCS and not your core industry?
What are the 5 types of inheritance in c ++?
How can I direct output to the printer?
Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?
What is integer constants?
main() { static char *s[]={"black","white","yellow","voilet"}; char **ptr[]={s+3,s+2,s+1,s}, ***p; p=ptr; **++p; printf("%s",*--*++p+3); }
1. What will be the output of the following programs. a) #include <stdio.h> Main() { Int x=4; While(x==1) { X=x-1; Printf(“%d”,x); --x; } }
Do pointers need to be initialized?
C program to find all possible outcomes of a dice?
what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;