lol, indeed. Thanks!
zsolt
@zsolt
Posts made by zsolt

RE: Don't understand the question
Why is this a wrong question? I have the same question. :)

RE: My recursive Java code with O(n) time and O(n) space
Because of encapsulation. Imagine
buildTreePostIn
as an API. Clients of this API should not be able to see inner workings (i.e. implementation) of this API (to keep the API clean and/or to minimize possible dependencies); that's whybuildTreePostIn(int[], int, int, int[], int, int, HashMap)
is hidden.As a good rule of thumb: always hide everything as much as possible (i.e. make it private) until you have an exact reason to make it more visible.

RE: Accepted O(n) solution
It visits each node just once hence the linear time complexity.
Even if you don't understand what the code does just notice that the only place where recursion happens is at:
int l = getHeight(root.left); int r = getHeight(root.right);
thus we will never visit the same node twice.

RE: I solved it using radix sort
Ok, so you have 31 bits. How many different numbers can you have on 31 bits? 2^31. How many iterations does you algorithm require? Number of numbers * number of bits, i.e. 2^31 * 31. If n=2^31 then 31 is logn. The time complexity of your algorithm is O(n*logn) and it's far from linear. This is not better than calling
Arrays.sort()
! 
RE: I solved it using radix sort
Ok, so you have 31 bits. How many different numbers can you have on 31 bits? 2^31. How many iterations does you algorithm require? Number of numbers * number of bits, i.e. 2^31 * 31. If n=2^31 then 31 is logn. The time complexity of your algorithm is O(n*logn) and it's far from linear.

RE: My java accepted solution
Accepted? It has both compile and runtime errors...

RE: Better solution than bruteforce?
Best explanation so far of the O(nw) algo. Thanks dude!

RE: Why does my code keep causing a time limit exceeded error?
count
isint
,sym
ischar
.It's not a
"" + int
vs.Integer.toString(int)
issue. It's aString
+int
vs.char
+int
issue.result += "" + count + sym
would have worked as well. If you addint
andchar
then the result will be the int value + the ascii value of the char...