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++
int DiffHeight(Tree *root, int min,int max, int height)
{
if(root == NULL)
return;
if(root->left == NULL && root->right == NULL)
{
if(height < min)
min = height;
if(height > max)
max = height;
}
else
{
DiffHeight(root->left, min, max, height+1);
DiffHeight(root->right, min, max, height+1);
}
}
void AllPossiblePaths(int **a, int m, int n, int currrow, int currcol, int i)
{
if(currrow < 0 && currrow >= m)
return;
else
{
printf("%d", a[i]);
AllPossiblePaths(a, m, n, currrow -1, currcol +1, i);
AllPossiblePaths(a, m, n, currrow +1, currcol, i);
AllPossiblePaths(a, m,n, currrow +1, currcol+1, i);
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int a[][] = {{1,2,3},{4,5,6},{7,8,9}};
for(int i=0; i< 3, i++)
{
AllPossiblePaths(a, 3, 3, 0, i, i);
}
return 0;
}
Will this function work. I am using DP here
SumSet(int sum, int *a, int n)
{
if(a[n] > sum)
{
//no need to choose this number
SumSet(sum, a, n-1);
}
else
{
//explore both the path, taking the number and not taking the number
SumSet(sum-a[n], a, n-1);
SumSet(sum, a, n-1);
}
}
Please let me know if I am doing something wrong here
Will this function work. I am using DP here
SumSet(int sum, int *a, int n)
{
if(a[n] > sum)
{
//no need to choose this number
SumSet(sum, a, n-1);
}
else
{
//explore both the path, taking the number and not taking the number
SumSet(sum-a[n], a, n-1);
SumSet(sum, a, n-1);
}
}
Please let me know if I am doing something wrong here
put the data in a hash with key as customer id. the value for the hash (chained) since there will be multiple entries will be the pages he visited
Let say I number pages
Homepage = 1
Shopping cart = 2
Listmania = 3
then for customer with id let say 1130 hash will have an entry like 1->4->3->2
after creating a hash scan all the customers and build a max heap for the count of seq
like for 1->4->3->2 seq will be
1->4->3 i.e 143
4->3->2 i.e 432
Lets take the initial cordinate system which is on 21 i.e. x=0, y=0 and 1 is at according to this system is x=2,y=-2
Now cordinate system changes to 1 therefore new cordinate system gets shifted to 2,-2
i.e to find (x,y) of any point subtract 2,-2 with x and y and if any of them is grater than 4 subtract 4 with it
i.e new cordinate becomes
x' = x - 2
if x'>4, x' = 4 - x'
y' = y - (-2)
similarly for y
Eg.
take example of 17 whose x=0, y = -4 according to old system
new x = 0-2 = 2
y = -4 -(-2) = -2
hence -2,-2
It is as simple as taking a k size array and populating it with first k points.
Now
if next element < arr[0]
then arr[0] = element
Call heapify i.e
check arr[0] with its children i.e. 2i and 2i+1 where i is the root.
Let me know if there is a problem, I will write a c++ code
tree* LCA(tree *root, int lvalue, int rvalue, int index)
{
static int lcaindex = 0;
static tree* lcaroot = root;
if(root == NULL)
return NULL;
else if((findnode(root->left,lvalue) && findnode(root->right, rvalue)) || (findnode(root->left,rvalue) && findnode(root->right, lvalue))
{
if(index > lcaindex)
{
lcaindex = index;
lcaroot = root;
}
}
else
{
LCA(root->left,lvalue,rvalue,index++);
LCA(root->right,lvalue,rvalue,index++);
}
return lcaroot;
}
bool FindString(char **str, int m, int n, char *wordToFind, int pos)
{
if(str[m,n] == wordToFind[pos])
{
if(strlen(wordToFind) == pos)
{
return true;
}
else
{
return FindString(str, m+1, n, wordToFind, pos+1) || FindString(str, m, n+1, wordToFind, pos+1) || FindString(str, m+1, n+1, wordToFind, pos+1)
}
}
else if( m>M || n >N)
return false;
else
return FindString(str, m+1, n, wordToFind, pos) || FindString(str, m, n+1, wordToFind, pos) || FindString(str, m+1, n+1, wordToFind, pos)
}
Please let me know if I am going wrong here
I am starting from (0,0).
Oh I am sorry. A little modification to the code. Please do let me know If I am making some mistake here.
Starting from x,y, the initial inputs for the array will be x, y
int fall =0;
int calProb(int n, int m, int **arr, int steps)
{
if( m<0 || n< 0)
{
fall++;
return 0;
}
else if(step ==0)
return 1;
else
{
return CallProb(n-1,m,**arr,step--) + CallProb(n,m-1,**arr, step--) + CallProb(n-1,m-1,**arr,step--);
}
}
Now we can calculate
Let say the output of this function be livProb i.e.
livProb = calProb(x,y, arr, n);
therfore living probability = livprob \ (livprob + fall)
TreeNode* CreateTree(TreeNode *root, int *arr, int l, int r)
{
if(l == r + 1 || r == l -1)
return NULL;
else
{
int mid = (l + r) / 2;
root = new TreeNode();
root->data = arr[mid];
root->left = CreateTree(root, arr, l, mid-1);
root->right = CreateTree(root, arr, mid+1, r);
}
return root;
}
this is what I have thought using DP. Please do let me know where I am wrong here
int Path(int *x, int m,int n)
{
if(x[m,n] == 1)
{
//no path
return 0;
}
if(m=0 && n=0)
{
//reached goal
return 1;
}
else
{
return Path(x,m-1,n) + Path(x,m,n-1) + Path(x,m-1,n-1);
}
}
Can we have a min heap of n pages where min page is the one which is least recently used.
- DashDash April 03, 2013