Yep thats N^2 , I did that too and didn’t bother with optimising cause it passed … It would work for 10^5 for most cases but one 
For a randomly generated tree, the height is usually proportional to lg(n)
but they will have worst case inputs as well…
Maybe you should read the date of the answer before copying from quora ![]()
so it should be “past 4-5 years” now 
Actually Agnishom it would be log_k(N) where , K is the lowest number of children per node … lg(N) is only applicable to binary trees … And trust me manual testing mein they would only consider the WORST CASE (you should’ve read the instructions, ) (even I should’ve
) dude move on !!!
Does anyone have any idea about the limit for the stack size to cause an overflow (is it included in the 512 MB)? I am getting a segmentation fault in test case 2_10 for wealth disparity.
You were right
How do you get 130? o.O
iii, jjj
nice loop variable names there _ /\ _
@warhawk_123, my solution - #include <stdio.h>#include <iostream>#include <vector>#include <algorithm> - Pastebin.com
I just wish I had thought of this during the test. I manually tested in on the test cases and it passed all with the longest one taking about 0.45 seconds.
The tester code is half baked just to get the stuff done in C# - using System;using System.Collections.Generic;using System.Linq;using Syst - Pastebin.com
Here’s my solution. I know its very messy but I was only focused on getting it right during the exam - /* Archit Rungta, 37004, Wealth Disparity*/#include <vector>#include <stdio. - Pastebin.com
Change what?
doesnt matter , n^2 will not even work with 10 seconds and O(n) will work with even in 1 second
thanks archit