saurabhroongta2
BAN USERCall this function with the second parameter as the level where that node is present.
cousin(node, depth)
{
if( depth == 0 )
{
// print the node value;
return;
}
else if( (depth == 1) && (node->left->value == givennode || node->right->value == givennode ) )
{
return;
}
cousin( node->left, depth--);
cousin( node->right, depth--);
}
Please check if this works::::
1. sort the array
2. if (arr[N/2] == arr[0])
return arr[0];
elseif(arr[N/2+1] == arr[N-1])
return[arr[N-1]
elseif(arr[N/2] == arr[N/2+1]
return(arr[N/2])
else
retrun(NULL);
Hi All,
the solution can be::::::
HRESULT ProcessData(PBYTE pDataBuffer, IN ULONG cbBufferSize)//
typedef struct tag_HEADER
{
ULONG cbTotalPacketLen;
ULONG cbThisChunkLen;
#define FLAG_FIRST_CHUNK_IN_PACKET 1
#define FLAG_LAST_CHUNK_IN_PACKET 2
ULONG flags;
} CHUNK_HEADER;
HRESULT ProcessData(PBYTE pDataBuffer, IN ULONG cbBufferSize) {
CHUNK_HEADER *header = (CHUNK_HEADER *) malloc(sizeof(CHUNK_HEADER));
static PBYTE *packet;
static int length;
header = (CHUNK_HEADER *)pDataBuffer;
if (header->flags == FLAG_FIRST_CHUNK_IN_PACKET) {
packet = NULL;
packet = (char *) malloc(header->cbTotalPacketLen);
length = header->cbThisChunkLen;
}
elseif(header->flags == FLAG_LAST_CHUNK_IN_PACKET) {
memcpy(packet+length, pDataBuffer+sizeof(CHUNK_HEADER), header->cbThisChunkLen);
ProcessPacket(packet);
packet = NULL;
length = 0;
}
else {
memcpy(packet+length, pDataBuffer+sizeof(CHUNK_HEADER), header->cbThisChunkLen);
}
}
what is this qsort function doing in this bentely's solution???
- saurabhroongta2 November 18, 2009I think her solution will work if instead of "node1->data == root->left->data && node2->data == root->right->data" condition she will use "(node1->data < root->data && node2->data > root->data) || (node1->data > root->data && node2->data < root->data)"
- saurabhroongta2 November 15, 2009Hi HariPriya,
I guess your solution will not work if node1 and node2 are not the immediate left and right(and vice versa) children of root.
But if they are not the immediate onces then their father's father shluld be searched.
Hi Taesung,
I think ur solution is equivalent to using the pointer variable of that type which is not supposed to be used....
1. reverse the whole string in O(n)
2. traverse the string and store the index of the spaces in an array in O(n)
3. Now reverse the string between every 2 consecutive indexes.(O(n))
please let me know if it will work ???
Hi Tejas,
We can sort this by BST also in O(nlogn) ???
X should be an even number
- saurabhroongta2 November 14, 2009what is "last" here??
- saurabhroongta2 November 14, 2009I will use a linked list to store the incoming streams rather than a array. Because it need to have a fast insertion and deletion which is not possible with the array.
- saurabhroongta2 November 13, 2009
probability of the same number coming out is very high:
- saurabhroongta2 January 17, 2012like R1=100 and R2=200
so for numbers like 1057,2057 ... it will return the same random number in that range.....