Reported August 2024
Nutanixdynamic programming

Min Cost To Collect All Points

Reported by candidates from Nutanix's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Nutanix OA. Under 2s to a working solution.
Founder's read

Nutanix hit you with Min Cost To Collect All Points in August 2024, and you're staring at a problem that looks like it wants greedy but doesn't. You've got a set of points, you start somewhere, and you need to visit all of them with minimum total distance. The trap is thinking you can just pick the nearest unvisited point each time. You can't. This is traveling salesman in disguise, and the only real solution is bitmask DP or brute force with pruning. StealthCoder will have the pattern locked when you're live.

Pattern and pitfall

The problem is a constrained TSP variant. Greedy fails because minimizing each step doesn't minimize the total path. You need dynamic programming with bitmask to track which points you've visited and what your current position is. State: dp[mask][i] = minimum cost to visit all points in the bitmask, ending at point i. Transition: try moving to each unvisited point and update the mask. The catch is the distance metric (usually Euclidean or Manhattan) and whether you return to the start. With n up to 12-15 points, bitmask DP runs in O(2^n * n^2), which is tight but viable. Most candidates freeze on the state definition. StealthCoder gives you the setup instantly so you can code without panic.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Min Cost To Collect All Points cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Nutanix's OA.

Nutanix reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Min Cost To Collect All Points FAQ

Is this really greedy or is it DP?+

It's labeled greedy but it's traveling salesman. Greedy fails. Use bitmask DP where the state is (visited set, current position) and the value is minimum cost. Greedy would only work if the problem had special structure like collinear points or a heap property.

What's the state definition?+

dp[mask][i] where mask is a bitmask of visited points and i is your current point. dp value is the minimum cost to reach that state. Initialize dp[1<<start][start] = 0. Iterate through all masks in increasing order and expand.

Do I have to return to the start?+

The problem text wasn't provided, but typical variants ask for the minimum cost path visiting all points, not necessarily returning. Read the problem carefully. If return is required, add the distance from your final point back to the start.

How do I compute distances between points?+

Assume Euclidean distance unless stated otherwise. sqrt((x2-x1)^2 + (y2-y1)^2). You can precompute all pairwise distances in an n*n matrix to avoid recalculating during DP.

What if n is large, like 20 or 25?+

Bitmask DP won't fit in memory or time. You'd need branch and bound, genetic algorithms, or heuristics. But Nutanix's OA usually caps n at 12-15. Check the constraints. If n > 15, the intended solution is not DP.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Nutanix.

OA at Nutanix?
Invisible during screen share
Get it