I invite you to take part in HackerRank HourRank 19 starting on April 2nd 2017. The contest duration is 1 hours. There will be three algorithmic problems of various difficulty.

The chief author of this round is torquecode. The chief tester is pkacprzak. Thanks to Piotr Gajowiak and wild_hamster for pre-solving the problems and giving valuable opinions.

The problems will have subtasks to make them interesting for everyone. I strongly recommend to read all the problems.

The contestants are ranked by score. If two contestants get the same score, the person who reached the score first is ranked higher.

Happy Coding!

Wow a 1 hour event again.......Thanks for the info :0 Hoping for better rating this time .

For the last question,instead of removing each edge and calculating the diameters of the 2 trees obtained..it would be sufficient to just remove edges incident on the center of the tree and which are part of diameter(ie only 2 edges). Although I'm not aware of the proof,I'm quite sure that this should also be correct.

If I understood your idea correctly, your solution would print 9 for this tree, but answer is 10.

Yes!The problem is very similar to this.

Third problem is similar to a COCI problem which I think is the reason why people solved it so quickly.

Are your certain that's correct? What would be your answer for this tree?

UPD: Don't know how to post images :-(

You probably meant to post this as a reply to shubhamgoyal__.

Indeed. I am sorry for my mistake.

Also, reducing this problem to calculating the longest path in every subtree (also for the subtrees "going up") is pretty easy, and the latter problem is incredibly standard and well known... So I would guess some of the fastest contestants just copied their solutions from some other problem which required the same thing, not necessarily the one you mentioned. I couldn't remember any of those problems though, had to implement it again :P

http://www.spoj.com/problems/TWOPATHS/

Can someone explain how to solve the second problem.

Read Nim

well if i got you right finding all combinations of v[b] ^ v[e] == stotalxor is the main idea of solution?

Nim game: first player can win if only if xor sum s[] elements is not zero.

But, our case need count winning situations of second player, so need achieve xor sum of s[] elements to zero, after remove s[b]...s[e] elements.

i.e.

s[0] xor s[1] xor ... xor s[b-1] xor s[e+1] xor ... s[n-1] == 0.

add xor to both sides to (s[b] xor s[b+1] xor .. s[e]) — gives

stotalxor = xor_sum(s[i], i= 0..n-1) = 0 xor xor_sum(s[j], j = b..e) = xor_sum(s[j], b..e).

xor_sum(s[j], j = b..e) = xor_sum(s[j], j = 0..b-1) xor xor_sum(s[j], j = 0..e)

Let v[k] = xor_sum(s[j], j =0..k-1);

so need find that (b,e) pairs (0 <= b <= e < n ), that v[b] ^ v[e+1] == stotalxor.

if we know

`e`

, so can calculate number of b, that 0 <= b <= e, and v[b] ^ v[e+1] == stotalxor. because,of b is xorcnt[ stotalxor ^ v[e+1] ].