thebiker925
BAN USER- 3of 3 votes
AnswersGiven a bst and a group of numbers g, check whether all the elements of g occur in the same path.
- thebiker925 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 2of 2 votes
AnswersGiven nxn boolean matrix (0's and 1's) .
- thebiker925 in United States
Find out whether there exist a row i and column j such that
1) all elemets of row i are zero's and
2) all elements of column j are 1's and
3)(i,j)th entry of the matrix can be either 0 or 1
Find out such a i and j exist or not .
complexity :O(n)| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm
thanks for the code. But I didnt get why we need 2 arrays of 600 count, we can just work with one array of 360 count? For example create the array of size 360, mark the temp array 1 for arrival -1 for departure and 0 if there is both at the same min. track the max sum in the next scan.
- thebiker925 September 22, 2013do we really need height?
int diameterHelper(bst* head, int& y)
{
if(head==0)
return 0;
int left=diameterHelper(head->Left,y);
int right= diameterHelper(head->Right,y);
if(y < left+right+1)
y =(left+right)+1;
if(left>right)
return left+1;
else
return right+1;
}
int Diameter(bst* head)
{
int result=0;
diameterHelper(head,result);
return result;
}
see the 3rd step, the (i,j)th entry of the matrix can be either 0 or 1
- thebiker925 September 11, 2013
ohh ok, Thanks!
- thebiker925 September 22, 2013