Блог пользователя _abstract_

Автор _abstract_, история, 4 года назад, По-английски

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.

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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.