codinglearner
BAN USERdont have exact ans bt its not the mirror tree
- codinglearner August 04, 2012@shondik
dats wat i cudnt figure out...:(
n confused
@shondik
bt in the normal bst we dont have the duplicates how cum the example taken valid then??
@samant.bit do dey expect the o/p to be 25 12 45 5 16 30 9???
- codinglearner August 03, 2012cud sum1 tell me the wat is the utility of chkin
if(a.b==0) and also y (a+b<0) is chkd??
yeah zero is the corrct ans.
here basically we are finding the smallest element in the array..
and since the partial initialization of the array is dun so all the uninitialized values vud be zero and thus zero is the rite ans
(only if v consider the typo)
else the ans vud be segmentation fault
if two temp arrays are not taken it wont b possible in single pass.
- codinglearner July 05, 2012@ashot madatyan please tell how could one generalize and conclude the no of initial groups into vich prob shud be subdivided
???
thnx in advance
the algo could go on like this....
1.scan the array in reverse order and create a min heap of k elements.
2.the element B[i] would be the element at the root of min heap.
3. now delete the element at A[K+i -1] and insert the element A[i-1]
4.reheapify the heap.
TC-O(nlogk)
the algo could go on like this....
1.scan the array in reverse order and create a min heap of k elements.
2.the element B[i] would be the element at the root of min heap.
3. now delete the element at A[K+i -1] and insert the element A[i-1]
4.reheapify the heap.
TC-O(nlogk)
i gues this should work
- codinglearner May 17, 2012or vice-versa
- codinglearner May 09, 2012doesnt it means dat the current node value b replaced jst by the sum of the right child recursively??
- codinglearner May 09, 2012@ newCoserInTown My algo works has O(n) and the question itself specifies the that the nos in the array are positive...that wasnt an assumption .However thnx for reminding me of the testcase i missed i.e sum being negative.
- codinglearner May 03, 2012#include<stdio.h>
void findsubarray(int *a,int n,int sum)
{int start=0,end=0;
int tempsum=0;
if(sum<a[0])
{
printf("not possible");
return;
}
for(int i=0;i<n;i++)
{
if(tempsum==sum)
break;
if(tempsum<sum && a[i]<sum)
{
tempsum+=a[i];
end=i;
}
if(tempsum>sum)
{
tempsum-=a[start];
start++;
}
}
if(tempsum==sum)
{
for(int i=start;i<=end;i++)
printf("%d\t",a[i]);
}
else
printf("not possible");
}
int main()
{
int a[]={1,3,5,6,8,9};
int n=6;
int sum=14;
findsubarray(a,n,sum);
}
are the elements expected to be in sorted order???
- codinglearner May 02, 2012is there any algo bettr than O(n^2)????
- codinglearner May 01, 2012is there any algo bettr than O(n^2)????
- codinglearner May 01, 2012backtracking!!!
- codinglearner March 13, 2012similar to find the kth smallest element in the tree....
- codinglearner March 13, 2012this is the pseudo code....
levelorder(struct node *root)
{
struct queue *q=createqueue();
if(root==NULL)
return;
levelorderutil(q,root);
}
levelorderutil(struct queue *q,struct node *root,int k)
{
if(root!=NULL)
enqueue(q,root);
if(k==0)
enqueue(q,NULL);
levelorderutil(q,root->left,k+1);
levelorderutil(q,root->right,k+1);
enqueue(q,NULL);
}
crkt me if i'm wrong.....
it can be done by the use of only one queue also...if the end of each level is marked by the null in the queue....
- codinglearner March 02, 201210
or genralizing for n nos--(n-1)n/2 in the worst case
int largestvaluesum(struct node *root,struct node **maxvaluenode)
{int maxsum;
if(root==NULL)
return 0;
int lsum=largestvaluesum(root->left,maxvaluenode);
int rsum=largestvaluesum(root->right,maxvaluenode);
if(maxsum<=max(lsum,rsum)+root->data)
{maxsum=max(lsum,rsum)+root->data;
*maxvaluenode=root;
}
return maxsum;
}
we can use hashing for the alphabets then it will be a O(n) algo simply
- codinglearner February 29, 2012in your code u r neglecting the case when the product of the three max nos is maximum..
- codinglearner February 28, 2012
RepMarciaGonzalez, abc at ADP
I am a diligent Encoding Clerk with a passion for precision and accuracy in data management. With a keen eye ...
ans shud b "abcd" i guess
- codinglearner August 19, 2012