pansophism
BAN USER- 0of 0 votes
Answersgiven a series of stock prices in an array. Pick when to buy and when to sell to gain max profit.
- pansophism
(This a the worst experience for me ever! It is just a simple max sum problem. The interviewer came in with his computer and kept smiling at it while his phone rings all the time. I couldn't even think. This guy totally screwed my interview.)| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
AnswersYou are given a binary tree in which each node contains a value Design an algorithm
- pansophism
to print all paths which sum up to that value Note that it can be any path in the tree
- it does not have to start at the root| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm
example would be, given stock prices like this:
9 2 5 6 6 1 3 7
we should buy at price 1 then sell at 7. we cannot buy at 1 then sell at 9 since it is in the past.
nice idea.
- pansophism June 20, 2011public static void sumSearch(Node nd1, Node nd2, sum){
if(nd2 == null){
search sum - nd1 in tree nd1;
if (found)
print;
else{
searchSum(nd1.left, nd1.right, sum);
}
}
if(nd1 == null){
search sum - nd2 in tree nd2;
if (found)
print;
else{
searchSum(nd2.left, nd2.right, sum);
}
}
if(nd1 + nd2 > sum){
sumsearch(nd1.left, nd2);
sumsearch(nd1, nd2.left);
} else if(nd1 + nd2 == sum){
print
} else {
sumSearch(nd1.right, nd2);
sumSearch(nd1, nd2.right);
}
}
space O(1)
- pansophism June 17, 2011nice copy.
- pansophism June 14, 2011n & (n+1) == 0
- pansophism June 14, 2011if you have input [1, 3].
Are you going to put 3 as left child or right?
classic
- pansophism June 13, 2011If we are treated in a rude way, shouldn't we just be tough to him too?
We are hired as a colleague not a slavery.
Criket?
- pansophism June 06, 2011smart choice
- pansophism June 06, 20111. fix size
2. random access
could be re-constructed use in-order and pre-order or in-order and post-order
- pansophism June 06, 2011public Linklist<Node> path = new LinkList<Node>();
int msp(Node root){
if(root == null)
return 0;
int leftSum = msp(root.left);
int rightSum = msp(root.right);
if(leftSum > rightSum){
add left path into linklist;
} else {
add right path into linklist;
}
int sum = root.value + max(leftSum, rightSum);
}
we can solve it by solving the longest common substring between the string and its reverse. That would be just a simple DP problem.
- pansophism June 03, 2011thumb up!
- pansophism May 28, 2011sounds like hashing to me
- pansophism May 23, 2011saw the solution before: Use XOR
int bit_swaps_required( int a, int b ) {
unsigned int count = 0;
for( int c = a ^ b; c != 0; c = c >> 1 ) {
count += c & 1;
}
return count;
}
bucket sort
- pansophism May 23, 2011fn = Phi^n / (Phi + 2)
- pansophism May 21, 2011@ftfish are you trying to remind overflow problem? or what?
- pansophism May 21, 2011holes are round? So if you want to cover it, use round manhole.
- pansophism May 20, 2011aggree
- pansophism May 20, 2011n^(1/2) ?
- pansophism May 20, 2011Not clear by question.
By making averages of two arrays equal, do you mean by re-arrange elements or just like above post did, just move the extra value?
retrieve layer by layer
- pansophism May 19, 2011There will not be 5 teams with 11 points.
Since the top 4 teams with 11 points are losing to each other and winning to all the rest.
The 5th team will be losing 4 points to top 4 teams. Total match is 14, it cannot got 11 points.
Full mark would be 14.
if team T got 13, that means it is possible an other team T1 win all the game except losing one to T(there two matches). T and T1 are all at first place with 13 wins.
if team T got 12, that means there are two situations:
a > it exists a team T3, wins all game(including the two lost by T), T is the second place.
b > it exists two teams, T4 and T5, they won T once, and T4 to T5 once and T5 to T4 once, they got 12 points too. So, will three are at fist place.
If team T got 11, that means it lost 3 games:
a > it exists a team T6, wins all game, including 2 of T. another team tie T7 to T got 12 points(lost one to T6).
b > it exists another 3 teams, all get 11 points. That's the minimum we can accept.
So 11 is the answer.
debugging will take most of time. Are they gonna give us a laptop or what?
- pansophism May 19, 2011word signature: hello -> e1l2h1o1, then put in hashmap
- pansophism May 18, 2011(2^n - n)*n! is the answer
- pansophism May 18, 2011in case n = 3, there are only 5 structures instead of 6, since there is one duplicate.
the solution could work upon proper change.
wonderful recursive solution.
- pansophism May 17, 20111. hashing
2. Tortoise and the Hare
hashing? then detect collision
- pansophism May 09, 2011sorry miss-understanding
brackets are not required in the tree.
You can rebuild the equation by operating on immediate children.
are you sure brackets are not included in the tree?
- pansophism April 21, 2011xor would be the answer.
a xor a == 0;
for(numbers in array first to second last){
i xor i + 1
}
to avoid deadlock, threads should request locks in a certain order.
- pansophism February 16, 2011I got on solution n(logn):
1. use 0 minus each element in the array, put result in a new array --- n
2. binary search each element in new array within old array, record distance. --- nlogn
3. pick the one with smallest distance --- n
won't work for
100 1 -2 -100
in-order is sufficient for this problem
- pansophism December 14, 2010agree
- pansophism December 14, 2010in-order + preorder
or
in-order + postorder
bitmap should be used here
- pansophism December 14, 2010Newton's method
- pansophism December 13, 2010hand waving
- pansophism December 13, 2010using dynamic programming
if a[i] >= max(a[0 ... i-1] then l(i) = l(i - 1) + 1, put a[i] into result array.
else l(i) = l(i-1);
or just use hashmap, insert into the map and wait for the first collision happen
- pansophism December 13, 2010
RepHello friends my name Neha Nanda from India Chandigarh city. Doing work in SEO line in Softsys company.
Rep
Repnancyhfloress, Computer Scientist at AMD
Hey there, I’m Nancy. I’m a small business owner living in Sunrise, FL 33323. I am a fan ...
Repabbyhgabb, Associate at Abs india pvt. ltd.
Develop fresh content for emails, web banners, site wide communication, and subject lines.Write stories, blogs and related content about ...
RepHi, I am Anne from Portsmouth, USA. I have been working as a freelance digital illustrator specialized in 3D character ...
RepI am an energetic sales professional with a track record of consistently increasing sales revenue in a competitive market. Contract ...
how many numbers are missing?
- pansophism June 29, 2011if it is one, xor.