## DashDash

BAN USER- -2of 2 votes

AnswersHow to print a variable 1000 times without using loops and recurssion

- DashDash in India| Report Duplicate | Flag | PURGE

Software Engineer / Developer - 0of 0 votes

AnswersWe have

- DashDash in India for Development

char *p = "abc";

I know we cant do p[0] = 'a'. What is the reason behind it?| Report Duplicate | Flag | PURGE

Software Engineer / Developer C++ - 0of 0 votes

AnswersWhat is the next number in the series

- DashDash in India

2,4,8,16,24...| Report Duplicate | Flag | PURGE

Goldman Sachs Applications Developer Brain Teasers - 0of 0 votes

Answersvoid copystring(char* dest, char *source)

- DashDash

{

while(*source != NULL)

{

*dest = *source;

dest++;

source++;

}

}

int _tmain(int argc, _TCHAR* argv[])

{

char input[10] = "hello";

char *dest;

dest = &input[1];

copystring(dest, input);

return 0;

}

What is the output of the program...| Report Duplicate | Flag | PURGE

Microsoft Software Engineer / Developer C++

void SumDiff(Tree *root, int num, int *Sum1, int *Sum2)

{

if(root != NULL)

{

if(num % 2 == 0)

{

*Sum2+= root->data;

SumDiff(root->left, num +1, Sum1, Sum2);

SumDiff(root->right, num +1, Sum1, Sum2);

}

else

{

*Sum1+= root->data;

SumDiff(root->left, num +1, Sum1, Sum2);

SumDiff(root->right, num +1, Sum1, Sum2);

}

}

}

Here is what I thought

Last element will be the largest

The diagonal just above the last element will have elements smaller to largest and greater than others

Eg.

I am taking a 3x3 matrix

4 9 11

5 13 15

6 16 25

Now 25 will be largest

Next diagonal elements are 16 and 15

Other next are 6 13 11

Hence we can calculate the kth max element by finding the diagonal where the kth number can be and then finding the kth element from that diagonal

void PrintDdistance(Tree *node, int d, const int D)

{

if(node == NULL)

return;

if(d == D)

Print the node

else

{

PrintDdistance(node->left, d+1, D);

PrintDdistance(node->right, d+1, D);

}

}

I doubt we can find the distance from the parent since only the node pointer is given

Scan the matrix and store the cell positions whose values are 0 in a separate array.

Now every year scan the array and for every element in the array check the adjacent values and if it is all 1 then remove the element from the array and change the matrix.

after k yrs the left elements in the array are the forests left

lets number every sequence like 1->3->8 = 138, so every sequence will be unique

Now let say the sequence with time is 1->3->6->3->5->4....

So the sequence combinations can be 136,363,635,354,........

Now counting the sequence which occurs most can be the answer

Please do let me know if I am wrong here.

We can divide the numbers in blocks and assign it to threads. Let say we get first 10 numbers we assign it to a thread which will give me a random number between 1-10. Now every thread will give me a random number between than range and the main thread then actually get the random number from the range of numbers provided by the threads.

- DashDash June 02, 2012Here is what I thought

Let say he starts from root and index = 0. Reduce index by 1 if he goes to left and increase index by 1 when goes to right. and enter into a hash with index as the key.

Now print the hash taking the min index and traversing to the max index.

int SumofRightTree(Tree *tree, bool isRight)

{

if(tree != NULL)

{

SumofRightTree(tree->left, false);

tree->data = tree->data + SumofRightTree(tree->right, true);

return tree->data;

}

else

return 0;

}

int _tmain(int argc, _TCHAR* argv[])

{

int arr[] = {30,10,5,20,50,40,60};

Tree *root= NULL;

for(int i=0;i<7; i++)

root = CreateTree(root, arr[i]);

SumofRightTree(root, true);

return 0;

}

int SumofRightTree(Tree *tree, bool isRight)

{

if(tree != NULL)

{

SumofRightTree(tree->left, false);

tree->data = tree->data + SumofRightTree(tree->right, true);

return tree->data;

}

else

return 0;

}

int _tmain(int argc, _TCHAR* argv[])

{

int arr[] = {30,10,5,20,50,40,60};

Tree *root= NULL;

for(int i=0;i<7; i++)

root = CreateTree(root, arr[i]);

SumofRightTree(root, true);

return 0;

}

int SumofRightTree(Tree *tree, bool isRight)

{

if(tree != NULL)

{

SumofRightTree(tree->left, false);

tree->data = tree->data + SumofRightTree(tree->right, true);

return tree->data;

}

else

return 0;

}

int _tmain(int argc, _TCHAR* argv[])

{

int arr[] = {30,10,5,20,50,40,60};

Tree *root= NULL;

for(int i=0;i<7; i++)

root = CreateTree(root, arr[i]);

SumofRightTree(root, true);

return 0;

}

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Can we have DP here

- DashDash February 17, 2013SP(m,n) = min(SP(m-1, n-1), SP(m-1,n), SP(m,n-1), SP(m+1,n+1), SP(m+1,n), SP(m,n+1)) + 1 if x[m,n] != 0;

if x[m,n] = 0 then return 0