hachyderm.io is one of the many independent Mastodon servers you can use to participate in the fediverse.
Hachyderm is a safe space, LGBTQIA+ and BLM, primarily comprised of tech industry professionals world wide. Note that many non-user account types have restrictions - please see our About page.

Administered by:

Server stats:

9.5K
active users

Šimon Tóth

Tuesday common C++ interview problem: Sum of distances to all nodes

Given a tree with n nodes, represented as a graph using a neighbourhood map, calculate the sum of distances to all other nodes for each node.

The node ids are in the range [0,n).

Solve it yourself: compiler-explorer.com/z/5nj1ej
Solution: compiler-explorer.com/z/59zxjq