alkatzo
BAN USER
Comments (5)
Reputation -5
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
Any two duplicate subtrees have at least 3 nodes in common - root, left and right. In order to answer this question it is enough to find 2 subtrees having those 3 nodes equal.
Construct a hash multimap. Every new node goes into the map. If same value already exists, check if left=left and right=right. Stop if found. That's all.
Comment hidden because of low score. Click to expand.
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Yeah, well, nothing to do with physics :-)
The algorithm would be :
1. start at time t0
1. find time interval ( dt ) to the first collision of 2 balls or of a ball with a table edge
2. recalculate positions of all balls at time t0 + dt. Change the velocities of the collided balls (if any), and remove the ball(s) that hit a table edge
3. repeat from step 1 until no more balls left on the table.
Recursive code in python
- alkatzo May 14, 2017