Minimum Cost Walk in Weighted Graph

Asked atMeesho
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
  1. 01Ask how a walk's cost is combined
  2. 02Identify whether revisits are allowed
  3. 03Group nodes by connectivity with DSU
  4. 04Aggregate the component invariant
  5. 05Answer disconnected and same-node cases separately

Reference answer

Then expect these follow-ups

  • Why can revisiting edges only decrease a bitwise AND?

    Tests: correctness reasoning

  • How would the problem change for simple paths?

    Tests: constraint adaptation

Free to read · better with Enzo

Practice this out loud with Enzo

Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.

Next question