← ALL NOTES
String

3970. Shortest Path With At Most K Consecutive Identical Characters

The run of identical labels is not a property of a node. It is a property of how you arrived there. That is the entire problem: ordinary Dijkstra over n nodes has nowhere to keep "and the last three characters I passed were all b", so it cheerfully takes a cheap edge that only becomes illegal two hops later.

Loading…