← Questions
Order people to maximize happiness from standing before their idol
0
I was asked this
No reports yet. Sign in to say where you were asked it.
There are n people and each one has an idol, another person in the group. A person earns a given happiness value when they stand to the left of their idol in the line. Return an ordering of everyone that makes the total happiness as large as possible.
Each person points to one idol, so the "idol" links form a graph with n nodes and n edges, and every component holds a cycle: not everyone on a cycle can be satisfied.
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
