_abstract_'s blog

By _abstract_, history, 4 years ago, In English

question:https://www.hackerrank.com/contests/hack-the-interview-vi-asia-pacific/challenges/constructing-a-tree/problem

i have tried a lot but not able to construct the tree. i am not able to understand the code please can any one make me understand in easy language.

  • Vote: I like it
  • +2
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

The solution is into $$$3$$$ parts:

  1. Making straight chain, so $$$1$$$ node each at a height of $$$0,1,\ldots,p$$$.

  2. Adding $$$n-p-2$$$ nodes at height $$$1$$$.

  3. Adding the remaining $$$1$$$ node at height which satisfy the score constraint.

Do read the tester's code instead, my code was an alternate lengthy solution.