john.matheus
BAN USER- 0of 0 votes
AnswersA table composed of N*M cells,each having a certain quantity of apples, is given. you start from the upper-left corner. At each step you can go down or right one cell.Design an algorithm to find the maximum number of apples you can collect ,if you are moving from upper-left corner to bottom-right corner.
- john.matheus in India| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm
So, how to do it in O(n)?
- john.matheus July 18, 2012To make the changes reflect to a pointer variable,double pointers are used.
- john.matheus July 16, 2012An ownership kind of thing is associated with a mutex. The thread which takes a lock,can release a lock.It is used to mutual exclusion on the same block.
Semaphore on the other hand, acts as a signaling mechanism. A thread can enter into critical section after receiving signal from some other thread.
In short, a lock can be released by some other thread apart from the thread which has acquired it.
Partition doesn't work for duplicate elements.
- john.matheus July 16, 2012both pointing to root.
- john.matheus July 16, 2012A recursive approach.
call isPalindrome(&root,root);
bool isPalindrome(struct node **left, struct node *right)
{
/* stop recursion here */
if (!right)
return true;
/* If sub-list is not palindrome then no need to
check for current left and right, return false */
bool isp = isPalindrome(left, right->next);
if (isp == false)
return false;
/* Check values at current left and right */
bool isp1 = (right->data == (*left)->data);
/* Move left to next node */
*left = (*left)->next; /* save next pointer */
return isp1;
}
Use BFS, but instead of printing the node values, push it to the stack.
Once BFS gets completed, print the stack.
One sphere can be fitted in a box with dimensions 10x10x10.
So, required number of spheres is 1000.
This one handles multiple digit repetitions also.
void compress(char* str)
{
int i,count,j,top=-1,rev;
for(i=0;str[i];)
{
j=i+1;
count=1;
while(str[j] && str[i]==str[j])
{
j++;count++;
}
str[++top]=str[i];
if(count>1 && count<10)
str[++top]=count+48;
else if(count>=10)
{
rev=0;
while(count)
{
rev=rev*10+count%10;
count/=10;
}
while(rev)
{
str[++top]=rev%10 + 48;
rev/=10;
}
}
i=j;
}
str[++top]='\0';
printf("%s",str);
}
Output: ideone.com/c37hE
- john.matheus July 15, 2012Is there any restriction that black coin will be placed on only black square?
If yes:
Choose 8 out of 32 for white coin.Same for black.
32C8 x 32C8
Use a temporary scratch array where each index will be having x^2 + y^2[of each D point].
Take a max-heap of size k & act accordingly.
The heap will contain k nearest points.
Repcarlawbartlett, Accountant at ASU
Managed a small team managing toy elephants for the underprivileged. A real dynamo when it comes to managing vashikaran mantra ...
not working.
- john.matheus July 18, 201210,2,18,20,17
Both form the same BST's. However,relative ordering of the elements greater than root are not same.