morezaei00
BAN USERDanish is pretty much creating a heap out of the tree since we need to flatten out the tree before copying it.
Interesting how languages like PHP do this with their serialize function. serialize(tree); and then unserialize(tree); it works on any object type.
Above seems to be a reasonable solution assuming that the elements are guaranteed to be in different arrays. It will add two more loops over a and b, with complexity of O(a.length) and O(b.length) respectively.
Overall the complexity is still O(a.length + b. length).
This is a great example of a question where it can just be blow off to a completely hard problem. The trick is that the inequalities are not implying anything.
@thelineofcode is basically comparing 2 x 2 and making sure the inequality holds.
I see 2 problems in this solution:
- morezaei00 February 27, 20141. In most programming languages this is close to an infinite loop because number/26 takes a long time to become 0, i.e. starts at x.yyy... x.zzz... and so on until 0. I would use floor(number/26)
2. you need to append the "x" before the outputstr because converting it back to number with outputstr+"x" will not give you the same answer.