ashwini verma
BAN USER
Comments (4)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
@arturo, @oOZz isn't deleting the node will require the node to looked up in array which is unsorted hence O(n) so delete isn't O(1) ??
- ashwini verma June 25, 2013Comment hidden because of low score. Click to expand.
0
of 2 vote
// Looks like I was logged in. So posting again.
fun(Node n) {
if (n == null) return 0;
int lval = fun(n.left), rval = fun(n.right);
n.value = lval - rval;
return lval + rval;
}
Comment hidden because of low score. Click to expand.
0
of 0 vote
Blahfoo, Good Answer !
I have another approach where I don't need any other memory -
1. count elements of each list,
2. find length diff
3. traverse smaller list from beginning and longer list after diff number of elements from begining.
4. compare both pointer while traversing both together. If equal, that is the merge point.
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
accessing every kth element will take k steps hence complexity will be O(kn). I don't think doubly link list solves this problem.
- ashwini verma June 27, 2013