Google | Onsite | Best Cities
Anonymous User
2363

You are given a list of cities with an associated attraction score.
You are also given a list of list of city pairs (A, B) signifying you can travel from A to B or B to A

Find a unique path which consists of 4 distinct cities so that the attraction score is the highest. Just need to return the sum of the attraction score.

What is the best way to do this? I struggled and I was hinted towards a solution where we write a 4-nested for-loop to go through each combination. This felt so inefficient.

Comments (9)