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
}


No Answer is Posted For this Question
Be the First to Post Answer

Post New Answer

More C Interview Questions

What is 'makefile' in C langauage? How it be useful? How to write a makefile to a particular program?

2 Answers  


/*what is the output for the code*/ void main() { int r; r=printf("naveen"); r=printf(); printf("%d",r); getch(); }

1 Answers   CDAC,


What is wrong with this initialization?

0 Answers  


What is the output of the following program #include<stdio.h> main() { int i=0; fork(); printf("%d",i++); fork(); printf("%d",i++); fork(); wait(); }

8 Answers   ADITI, Adobe,


Do you know what is a programing language ?

0 Answers  






Difference between Function to pointer and pointer to function

0 Answers  


1 1 1 1 2 1 1 3 3 1 1 4 6 4 1

1 Answers  


Can the curly brackets { } be used to enclose a single line of code?

0 Answers  


Can include files be nested?

0 Answers  


What does 3 mean in texting?

0 Answers  


What is the modulus operator?

0 Answers  


what does ‘Bus Error’ mean?

1 Answers   ABC,


Categories